Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: pin scoped field ownership and angle-bracket citations in the volume contract (#4136)
Adam Eivy621531920616
diff --git a/server/services/pipeline/arcPlanner/promptContractHelpers.js b/server/services/pipeline/arcPlanner/promptContractHelpers.jsindex fb3ab66b12..0e75b0b455 100644--- a/server/services/pipeline/arcPlanner/promptContractHelpers.js+++ b/server/services/pipeline/arcPlanner/promptContractHelpers.js@@ -22,18 +22,29 @@ const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..'export const readShippedPrompt = (name) =>readFile(join(REPO_ROOT, 'data.reference', 'prompts', 'stages', name), 'utf-8');+const IDENTIFIER = /^[a-z][A-Za-z0-9]*$/;+/*** Candidate record-field identifiers a prompt cites in backticks. Strips the* illustrative value a check may attach (`episodeCountTarget: 12`) and the* array marker (`issues[]`) so the bare identifier is what gets tested. Only* single lowerCamelCase identifiers are candidates — JSON blobs, dotted paths* (`arc.themes`), kebab vocabulary, and prose fragments are not record fields.+ *+ * Angle-bracket placeholders inside the span are collected too: a `location`+ * form like `episode:<arcPosition>` names a real record field on its right-hand+ * side, and splitting at the colon would otherwise discard it — leaving a+ * substituted placeholder free to cite a field nothing renders.*/export const backtickedTokens = (markdown) => {const out = new Set();for (const match of markdown.matchAll(/`([^`\n]+)`/g)) {- const token = match[1].split(':')[0].replace(/\[\]$/, '').trim();- if (/^[a-z][A-Za-z0-9]*$/.test(token)) out.add(token);+ const span = match[1];+ const token = span.split(':')[0].replace(/\[\]$/, '').trim();+ if (IDENTIFIER.test(token)) out.add(token);+ for (const placeholder of span.matchAll(/<([A-Za-z][A-Za-z0-9]*)>/g)) {+ if (IDENTIFIER.test(placeholder[1])) out.add(placeholder[1]);+ }}return out;};diff --git a/server/services/pipeline/arcPlanner/volumeVerifyPromptContract.test.js b/server/services/pipeline/arcPlanner/volumeVerifyPromptContract.test.jsindex ba7249fc8a..d7ca1ab97a 100644--- a/server/services/pipeline/arcPlanner/volumeVerifyPromptContract.test.js+++ b/server/services/pipeline/arcPlanner/volumeVerifyPromptContract.test.js@@ -32,17 +32,40 @@ const NON_FIELD_TOKENS = new Set([// `location` VALUE forms (`episode:3`, `episode:2-3`, bare `volume`), not// field names.'episode', 'volume',+ // The ordinal placeholder in the `episode:<n>-<n+1>` boundary form.+ 'n',]);// The prompt scores an issue at whichever depth it has, so BOTH branches of the// leaf are legitimately citable: `beats` on an LLM-expanded issue, `synopsis` on// an un-expanded one.-const renderableFields = () => new Set([+const issueLeafFields = () => new Set([...Object.keys(renderVolumeIssue({ stages: { idea: { output: 'beat sheet' } } })),...Object.keys(renderVolumeIssue({ stages: { idea: { input: 'seed synopsis' } } })),+]);++const renderableFields = () => new Set([+ ...issueLeafFields(),...Object.keys(renderVolumeFields({})),]);+// Citations the checklist makes in a SPECIFIC scope. The union assertion below+// only proves a cited field is rendered somewhere, which is blind to the case+// codex flagged: `synopsis` exists on both renderers, so either side could drop+// it and the other would mask the loss. These pin the owner. New tokens still+// get caught by the union check — this table only has to carry the names the+// generic scan cannot attribute on its own.+const SCOPED_CITATIONS = [+ // "Each entry has either `beats` … OR just `synopsis`" — the issue leaf.+ ['beats', 'issue leaf', issueLeafFields],+ ['synopsis', 'issue leaf', issueLeafFields],+ ['arcPosition', 'issue leaf', issueLeafFields],+ // Checks #1/#4/#5 read these off the volume node.+ ['logline', 'volume node', () => new Set(Object.keys(renderVolumeFields({})))],+ ['synopsis', 'volume node', () => new Set(Object.keys(renderVolumeFields({})))],+ ['endingHook', 'volume node', () => new Set(Object.keys(renderVolumeFields({})))],+];+const unrenderableIn = (markdown, renderable) => [...backtickedTokens(markdown)].filter((token) => !NON_FIELD_TOKENS.has(token) && !renderable.has(token));@@ -62,6 +85,20 @@ describe('pipeline-volume-verify prompt ↔ buildVolumeVerifyContext contract',expect(unrenderableIn(cited, renderableWithoutBeats)).toEqual(['beats']);});+ it.each(SCOPED_CITATIONS)('renders %s on the %s the checklist reads it from', (field, _scope, rendered) => {+ expect([...rendered()]).toContain(field);+ });++ it('catches a scoped drop the other renderer would mask (bypass probe)', () => {+ // `synopsis` lives on BOTH renderers, so the union assertion alone cannot+ // see the issue leaf losing it — the volume node's copy keeps the union+ // satisfied while every beat/synopsis-depth check silently loses its input.+ const leafWithoutSynopsis = new Set([...issueLeafFields()].filter((f) => f !== 'synopsis'));+ const union = new Set([...leafWithoutSynopsis, ...Object.keys(renderVolumeFields({}))]);+ expect(union.has('synopsis')).toBe(true); // masked by the volume node…+ expect(leafWithoutSynopsis.has('synopsis')).toBe(false); // …but caught here.+ });+it('renders every {{volume.*}} field the prompt interpolates', async () => {const markdown = await readShippedPrompt(PROMPT);const rendered = new Set(Object.keys(renderVolumeFields({})));