|
1 | 1 | import assert from "node:assert/strict" |
2 | 2 | import { readFile } from "node:fs/promises" |
3 | 3 | import test from "node:test" |
| 4 | +import { assembleStandaloneDemoPrompt } from "../scripts/lib/demo-prompt.mjs" |
4 | 5 | import { validateSnapshotPolicy } from "../scripts/lib/snapshot-policy.mjs" |
5 | 6 | import { validateCustomTheme } from "../scripts/lib/theme-contrast.mjs" |
6 | 7 |
|
7 | 8 | const readJson = async (file) => JSON.parse(await readFile(file, "utf8")) |
| 9 | +test("demo scheduled-task prompts are standalone and embed the complete contract", async () => { |
| 10 | + const registry = await readJson("config/sources.json") |
| 11 | + const definition = registry.sources.find((source) => source.id === "money:pulse") |
| 12 | + const [basePrompt, domainPrompt, snapshotSchema, uiBlocksSchema, domainSchema, llmContract, privacyContract] = await Promise.all([ |
| 13 | + readFile("prompts/base-worker.md", "utf8"), |
| 14 | + readFile(definition.prompt, "utf8"), |
| 15 | + readJson("schemas/snapshot.schema.json"), |
| 16 | + readJson("schemas/ui-blocks.schema.json"), |
| 17 | + readJson(definition.schema_ref), |
| 18 | + readFile("docs/llm-contract.md", "utf8"), |
| 19 | + readFile("docs/privacy.md", "utf8"), |
| 20 | + ]) |
| 21 | + const prompt = assembleStandaloneDemoPrompt({ |
| 22 | + basePrompt, |
| 23 | + domainPrompt, |
| 24 | + definition, |
| 25 | + snapshotSchema, |
| 26 | + uiBlocksSchema, |
| 27 | + domainSchema, |
| 28 | + llmContract, |
| 29 | + privacyContract, |
| 30 | + }) |
| 31 | + |
| 32 | + assert.match(prompt, /This is a standalone Zaati OS prompt/) |
| 33 | + assert.match(prompt, /You are a registered Zaati OS snapshot worker/) |
| 34 | + assert.match(prompt, /Use only user-approved normalized totals/) |
| 35 | + assert.match(prompt, /registered for source money:pulse and worker money-pulse-daily/) |
| 36 | + assert.doesNotMatch(prompt, /Set money:pulse to money:pulse/) |
| 37 | + assert.match(prompt, /"id": "money:pulse"/) |
| 38 | + assert.match(prompt, /"worker_id": "money-pulse-daily"/) |
| 39 | + assert.match(prompt, /"target_path": "data\/snapshots\/money\/pulse/) |
| 40 | + assert.ok(prompt.includes(JSON.stringify(snapshotSchema, null, 2))) |
| 41 | + assert.ok(prompt.includes(JSON.stringify(uiBlocksSchema, null, 2))) |
| 42 | + assert.ok(prompt.includes(JSON.stringify(domainSchema, null, 2))) |
| 43 | + assert.doesNotMatch(prompt, /base-worker\.md/) |
| 44 | + assert.doesNotMatch(prompt, /\{\{SOURCE_ID\}\}|\{\{WORKER_ID\}\}/) |
| 45 | + assert.deepEqual([...new Set(prompt.match(/\{\{[A-Z_]+\}\}/g))].sort(), ["{{CODE_REPOSITORY}}", "{{DATA_REPOSITORY}}", "{{TIMEZONE}}"]) |
| 46 | +}) |
8 | 47 | test("safe UI contract exposes only audited block kinds", async () => { |
9 | 48 | const schema = await readJson("schemas/ui-blocks.schema.json") |
10 | 49 | const kinds = schema.$defs.block.oneOf.map((item) => item.$ref.split("/").at(-1)).sort() |
|
0 commit comments