{"version":3,"file":"conformance.mjs","names":[],"sources":["../../../src/batteries/skills/conformance/index.ts"],"sourcesContent":["/**\n * Conformance suite for {@link SkillSource} implementations.\n *\n * This is a deep-import-only entrypoint. It has no test-framework dependency and is not\n * re-exported by the skills barrel.\n *\n * @module @nhtio/adk/batteries/skills/conformance\n */\n\nimport type { SkillDescriptor } from '../types'\nimport type { DiscoveredSkill, SkillSource } from '../contracts'\n\nconst assert: (condition: boolean, message: string) => asserts condition = (condition, message) => {\n  if (!condition) throw new Error(message)\n}\n\n/** Run the common SkillSource contract checks against a fresh source. */\nexport const runSkillSourceConformance = async (\n  label: string,\n  makeSource: () => SkillSource | Promise<SkillSource>\n): Promise<void> => {\n  const expectedDescriptor: SkillDescriptor = {\n    id: 'demo',\n    name: 'Demo',\n    description: 'A conformance skill',\n    version: '1.0.0',\n  }\n\n  const discoverOne = async (source: SkillSource, caseName: string): Promise<DiscoveredSkill> => {\n    const discovered: DiscoveredSkill[] = []\n    for await (const value of source.discover()) discovered.push(value)\n    assert(\n      discovered.length === 1,\n      `SkillSource conformance [${label}] ${caseName}: discover() must yield exactly one skill`\n    )\n    return discovered[0]\n  }\n\n  {\n    const caseName = 'discovery'\n    const source = await makeSource()\n    const iterable = source.discover()\n    assert(\n      typeof iterable?.[Symbol.asyncIterator] === 'function',\n      `SkillSource conformance [${label}] ${caseName}: discover() must yield an async iterable`\n    )\n    const ref = await discoverOne(source, caseName)\n    assert(\n      ref.id === 'demo' &&\n        ref.version === '1.0.0' &&\n        ref.name === 'Demo' &&\n        ref.description === 'A conformance skill',\n      `SkillSource conformance [${label}] ${caseName}: discover() must preserve the expected skill reference`\n    )\n  }\n\n  {\n    const caseName = 'descriptor'\n    const source = await makeSource()\n    const ref = await discoverOne(source, caseName)\n    const descriptor = await source.descriptor({ ...ref, sourceId: source.id })\n    assert(\n      JSON.stringify(descriptor) === JSON.stringify(expectedDescriptor),\n      `SkillSource conformance [${label}] ${caseName}: descriptor() must match the discovered id, name, description, and version`\n    )\n  }\n\n  {\n    const caseName = 'body and stat'\n    const source = await makeSource()\n    const ref = await discoverOne(source, caseName)\n    const skillRef = { ...ref, sourceId: source.id }\n    const bytes = await new Response(await source.read(skillRef)).arrayBuffer()\n    assert(\n      new TextDecoder().decode(bytes) === '\\nBody\\n',\n      `SkillSource conformance [${label}] ${caseName}: read() must return the expected body as bytes`\n    )\n    const stat = await source.stat(skillRef)\n    assert(\n      stat.size === bytes.byteLength,\n      `SkillSource conformance [${label}] ${caseName}: stat().size must equal the body byte length`\n    )\n    assert(\n      stat.version === '1.0.0',\n      `SkillSource conformance [${label}] ${caseName}: stat().version must match the discovered version`\n    )\n  }\n}\n"],"mappings":";AAYA,IAAM,UAAsE,WAAW,YAAY;CACjG,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,OAAO;AACzC;;AAGA,IAAa,4BAA4B,OACvC,OACA,eACkB;CAClB,MAAM,qBAAsC;EAC1C,IAAI;EACJ,MAAM;EACN,aAAa;EACb,SAAS;CACX;CAEA,MAAM,cAAc,OAAO,QAAqB,aAA+C;EAC7F,MAAM,aAAgC,CAAC;EACvC,WAAW,MAAM,SAAS,OAAO,SAAS,GAAG,WAAW,KAAK,KAAK;EAClE,OACE,WAAW,WAAW,GACtB,4BAA4B,MAAM,IAAI,SAAS,0CACjD;EACA,OAAO,WAAW;CACpB;CAEA;EACE,MAAM,WAAW;EACjB,MAAM,SAAS,MAAM,WAAW;EAEhC,OACE,OAFe,OAAO,SAEf,IAAW,OAAO,mBAAmB,YAC5C,4BAA4B,MAAM,IAAI,SAAS,0CACjD;EACA,MAAM,MAAM,MAAM,YAAY,QAAQ,QAAQ;EAC9C,OACE,IAAI,OAAO,UACT,IAAI,YAAY,WAChB,IAAI,SAAS,UACb,IAAI,gBAAgB,uBACtB,4BAA4B,MAAM,IAAI,SAAS,wDACjD;CACF;CAEA;EACE,MAAM,WAAW;EACjB,MAAM,SAAS,MAAM,WAAW;EAChC,MAAM,MAAM,MAAM,YAAY,QAAQ,QAA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