* feat(core): add configurable mock responses for stub AI services
Adds AiMockConfigLoader, a shared mock-response config file (path via
AI_MOCK_CONFIG env var or floci.ai-mock-config-file) that lets callers
override Textract/Comprehend/Rekognition's fixed stub responses on a
per-call basis, so application logic that branches on detection
results (e.g. "escalate if sentiment is NEGATIVE") can be exercised
end-to-end against floci. Mirrors Step Functions' SFN_MOCK_CONFIG
mechanism (same mtime-cached reload without restart), but is shared
across three services and never throws: a missing file, unset env
var, or no matching entry all fall back to the existing default stub,
since mocking here is opt-in on top of an always-available default,
not the only way to invoke an action.
Lookup keys: Comprehend keys on the exact Text value; Textract and
Rekognition key on "<Bucket>/<Name>" from S3Object (a Bytes-backed
image/document has no such key, so mocking only applies to
S3Object-based calls). CompareFaces keys off SourceImage only. The
Textract async Start*/Get* job flow does not support mocking.
Closes#2764
* fix(core): catch unchecked exceptions when loading AI mock config
Path.of(path) throws InvalidPathException (unchecked) for a malformed
path string, and filesystem access can raise other unchecked
exceptions IOException alone doesn't cover. load() only caught
IOException, so a bad AI_MOCK_CONFIG value would propagate past the
loader and turn a normal Comprehend/Textract/Rekognition request into
a 500 — the exact opposite of this loader's contract (mocking is
optional; it must never break the default stub). Wrapped the load
logic in an outer catch (RuntimeException) that falls back the same
way the existing IOException cases already do.
Addresses review feedback on #2765.
* feat(comprehend): add Amazon Comprehend sync text-analysis actions
Implements DetectSentiment, DetectKeyPhrases, DetectDominantLanguage,
DetectPiiEntities, and ContainsPiiEntities as fixed AWS-shaped stub
responses over the real JSON 1.1 wire protocol
(X-Amz-Target: Comprehend_20171127.*). Input validation (Text and
LanguageCode required, LanguageCode checked against Comprehend's
supported set) matches real API behavior and raises
InvalidRequestException/UnsupportedLanguageException per
botocore's declared error shapes.
The async job/model-training surface (DocumentClassifier,
EntityRecognizer, Flywheel, Dataset, Endpoint) and DetectEntities/
DetectSyntax are out of scope for this PR. Real (non-stub) detection
logic is planned as a follow-up once this lands.
Closes#2660
* fix(comprehend): restrict PII detection to en/es language codes
DetectPiiEntities and ContainsPiiEntities were validated against the
full 12-language set shared with DetectSentiment/DetectKeyPhrases, but
AWS's own operation docs for DetectPiiEntitiesRequest.LanguageCode
state PII detection only supports English (en) and Spanish (es).
Split the allowlist so the two PII operations reject other languages
with UnsupportedLanguageException, matching real Comprehend behavior.
Addresses review feedback on #2674.
* fix(comprehend): reject non-string Text/LanguageCode as SerializationException
getStringField() coerced any JSON value via asText() instead of
enforcing the modeled string type, so a numeric or boolean Text/
LanguageCode silently succeeded instead of being rejected. Reuses the
codebase's existing SerializationException convention (see
JsonErrorResponseUtils.createSerializationErrorResponse()) since a
wrong-typed field is a shape/marshalling mismatch caught before
business logic runs, distinct from a missing field (InvalidRequestException,
a modeled business error). Scoped to ComprehendJsonHandler only.
Addresses review feedback on #2674.