Files
agents-marketplace/tests/fixtures/supplier-side/sample-config.ts
FilipBl4gojevic 2b2295b7ed fix(ocr): review pass — min-ada floor regression test, auth-before-parse, failure-path reconciliation, disclosure label coverage
Fixes 2 critical, 2 important, and 5 minor findings from review of 069edcb:

- C1: add a happy-path test that reaches postOcrEscrow.ts's escrowLockFloor
  call and asserts the locked amount; verified it fails against a bare
  economicTotal and passes against the real code.
- C2: gate /v1/ocr/extract (auth + rate limits) before the 16mb body parser
  so an unauthenticated caller can no longer force a full buffer/JSON.parse.
- I2: hoist result/used/escrowRef in the OCR one-shot handler so the failure
  path records escrow_ref/supplier/cost when an escrow was actually posted,
  and emit an ocr_failed structured log line mirroring ocr_settled.
- I3: export venueAttribution and cover its sanitization directly; add a
  stubbed happy-path route test asserting the first-party-brokered
  disclosure label reaches the response.
- Minor: drop unused hfWeightsSource end to end, rename a misleading test,
  make the OCR capability template's pinning language conditional on the
  self-hosted upstream, tighten the /v1/ocr path-prefix guard, and make
  preflight's required_lovelace use the same escrowLockFloor the builder
  locks (exported from the shared tx barrel for gateway use).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 17:12:12 +02:00

99 lines
2.8 KiB
TypeScript

/**
* Supplier-side sample config fixture — M1-C RED phase
*
* Provides a deterministic SupplierConfig for test injection.
* Built INDEPENDENTLY from buyer-side fixtures. No shared helpers.
*/
import type { SupplierConfig } from "../../../supplier/src/config.js";
import { SUPPLIER_PKH, SUPPLIER_PRIVATE_KEY_HEX } from "./wallet-keys.js";
/** The advert UTxO that this supplier's config points at. */
export const SAMPLE_ADVERT_TX_HASH = "b".repeat(64);
export const SAMPLE_ADVERT_INDEX = 0;
/** A deterministic valid 64-char hex tx hash for use in escrow refs. */
export const SAMPLE_ESCROW_TX_HASH = "f".repeat(64);
/** Full supplier config used in route handler tests. */
export function buildSampleConfig(): SupplierConfig {
return {
supplierPrivKeyHex: SUPPLIER_PRIVATE_KEY_HEX,
ogmiosUrl: "ws://localhost:1337",
ollamaUrl: "http://localhost:11434",
advertRef: {
txHash: SAMPLE_ADVERT_TX_HASH,
index: SAMPLE_ADVERT_INDEX,
},
networkId: 0,
port: 8080,
ollamaTimeoutMs: 120_000,
piperUrl: "",
piperTimeoutMs: 120_000,
capabilityKind: "chat",
maxChatSessions: 1,
chatSettleMode: "full",
liveChain: false,
};
}
/** TTS variant: same wallet/chain plumbing, capabilityKind="tts" + Piper URL set. */
export function buildSampleTtsConfig(): SupplierConfig {
return {
...buildSampleConfig(),
ollamaUrl: "",
piperUrl: "http://piper.fake",
capabilityKind: "tts",
};
}
/** OCR variant: OpenAI-compatible vision upstream, capabilityKind="ocr". */
export function buildSampleOcrConfig(): SupplierConfig {
return {
...buildSampleConfig(),
ollamaUrl: "",
openaiBaseUrl: "http://vllm.fake:8000",
openaiApiKey: "",
openaiTimeoutMs: 180_000,
openaiMaxTokens: 0,
openaiReasoningDisabled: false,
capabilityKind: "ocr",
ocrUpstream: "openai-vision",
datalabApiKey: "",
datalabBaseUrl: "https://www.datalab.to",
datalabMode: "accurate",
datalabTimeoutMs: 120_000,
ocrPromptOverride: "",
hfModelRevision: "",
revisionProbeUrl: "",
revisionProbeMode: "off",
};
}
/** Datalab-hosted OCR variant (OCR_UPSTREAM=datalab). */
export function buildSampleDatalabOcrConfig(): SupplierConfig {
return {
...buildSampleOcrConfig(),
openaiBaseUrl: "",
ocrUpstream: "datalab",
datalabApiKey: "dl-test-key",
revisionProbeMode: "per_job",
};
}
/** Env map matching the sample config above, for loadConfig() unit tests. */
export function buildSampleEnv(): Record<string, string> {
return {
SUPPLIER_PRIV_KEY_HEX: SUPPLIER_PRIVATE_KEY_HEX,
OGMIOS_URL: "ws://localhost:1337",
OLLAMA_URL: "http://localhost:11434",
ADVERT_REF: `${SAMPLE_ADVERT_TX_HASH}#${SAMPLE_ADVERT_INDEX}`,
NETWORK_ID: "0",
PORT: "8080",
OLLAMA_TIMEOUT_MS: "120000",
};
}
/** The pkh embedded in the sample config. */
export { SUPPLIER_PKH };