From 13d79fde1bac0e98d1919c176cfd255f66201e10 Mon Sep 17 00:00:00 2001 From: Adrian Webb Date: Fri, 30 Oct 2026 00:50:15 -0400 Subject: [PATCH 1/2] test: reproduce lost shared context in acting and review --- .../shared-proposal-context.test.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/unit/control-plane/capacity/execution/architecture/contributions/shared-proposal-context.test.ts b/tests/unit/control-plane/capacity/execution/architecture/contributions/shared-proposal-context.test.ts index 261872e6e..5d3ad8623 100644 --- a/tests/unit/control-plane/capacity/execution/architecture/contributions/shared-proposal-context.test.ts +++ b/tests/unit/control-plane/capacity/execution/architecture/contributions/shared-proposal-context.test.ts @@ -13,6 +13,32 @@ import { canonicalOfferBuildInput, candidate, gitRef, permissions as grantedPerm const sourceRef = { store: 'treedx', model: 'proposal', id: 'proposal', revision: 1, digest: `sha256:${'a'.repeat(64)}`, repository: 'repository', commit: 'b'.repeat(40), path: 'proposals/one.mdx' }; const permissions = { content: { read: ['proposal', 'decision'], write: [] }, tools: ['source.read'] }; +it('retains shared exact proposal context for acting and reviewing without importing peer workspace references', async () => { + const proposal = readyContributionProposal(), item = proposal.executionPlan.workItems[0]!; + const own = { store: 'git', model: 'repository', id: 'selected-source', repository: 'treeseed-ai/project', commit: 'c'.repeat(40) }; + const evidence = { ...own, id: 'historical-source', commit: 'd'.repeat(40) }; + const objective = { store: 'treedx', model: 'objective', id: 'related', repository: 'repository', commit: 'e'.repeat(40), path: 'objectives/related.mdx' }; + const discussion = { ...objective, model: 'discussion-message', id: 'planning', path: 'discussion-messages/plan/one.mdx' }; + const peer = { ...own, id: 'peer-source', repository: 'treeseed-ai/peer', commit: 'f'.repeat(40) }; + Object.assign(proposal, { objectiveRefs: [objective], evidenceRefs: [evidence], discussionRef: discussion, + executionPlan: { workItems: [{ ...item, contextRefs: [own] }, { ...item, id: 'peer-item', contextRefs: [peer] }] } }); + const content = `---\n${stringify(proposal)}---\n`, exact = { ...sourceRef, + digest: `sha256:${createHash('sha256').update(content).digest('hex')}` }; + gateway.readRepositoryFile.mockResolvedValue({ resolvedRef: exact.commit, file: { content, frontmatter: proposal } }); + const store = { getGovernanceProposal: async () => ({ id: 'proposal', projectId: 'project', teamId: 'team' }), + getProjectTreeDxLibrary: async () => ({ repositoryId: 'repository' }) }; + const held = structuredClone(proposal); + for (const kind of ['acting', 'reviewing']) { + const node = { id: `${kind}-selected`, kind, workItemId: item.id, sourceRef: exact, teamId: 'team', projectId: 'project' }; + const before = structuredClone(node), refs = await workItemContext(store, node as never); + expect(refs).toEqual([own, objective, evidence, discussion]); + expect(refs).not.toContainEqual(peer); + // The selected item's current source remains ahead of historical evidence. + expect(refs.find(ref => ref.store === 'git')?.commit).toBe(own.commit); + expect(node).toEqual(before); + } + expect(proposal).toEqual(held); +}); it('includes exact accepted scope for Git-only work without general content authority', () => { const exact = structuredClone(candidate), decision = { ...assignmentSource, model: 'decision', id: 'accepted', path: 'decisions/accepted.mdx' }; exact.node.requestedPermissions.content.read = []; From 25d34bdfd2787113e38749390a76230f2edfcaf6 Mon Sep 17 00:00:00 2001 From: Adrian Webb Date: Fri, 30 Oct 2026 00:58:27 -0400 Subject: [PATCH 2/2] fix: carry shared proposal context into acting and review --- .../scenes/component-boundaries.scene.yaml | 6 ++ guarantees/verifiers/golden.verifiers.yaml | 10 +++ .../services/build/ready-execution-node.ts | 9 ++- .../proposal-source-context-native.test.ts | 64 ++++++++++++++++++- .../architecture/proposal-native-fixture.ts | 6 +- 5 files changed, 89 insertions(+), 6 deletions(-) diff --git a/guarantees/agent/golden/scenes/component-boundaries.scene.yaml b/guarantees/agent/golden/scenes/component-boundaries.scene.yaml index f592a157b..5fd714650 100644 --- a/guarantees/agent/golden/scenes/component-boundaries.scene.yaml +++ b/guarantees/agent/golden/scenes/component-boundaries.scene.yaml @@ -102,6 +102,12 @@ workflow: - id: reviewed-predecessor-read-scope action: { verifier: api.golden.reviewed-predecessor-read-scope } expect: { status: passed } + - id: shared-acting-proposal-context + action: { verifier: api.golden.shared-acting-proposal-context } + expect: { status: passed } + - id: shared-acting-proposal-context-native + action: { verifier: api.golden.shared-acting-proposal-context-native } + expect: { status: passed } - id: estimate-branch-contention action: { verifier: api.golden.estimate-branch-contention } expect: { status: passed } diff --git a/guarantees/verifiers/golden.verifiers.yaml b/guarantees/verifiers/golden.verifiers.yaml index 42d236593..15c7b8f24 100644 --- a/guarantees/verifiers/golden.verifiers.yaml +++ b/guarantees/verifiers/golden.verifiers.yaml @@ -161,6 +161,16 @@ verifiers: ownerPackage: "@treeseed/api" testFile: tests/unit/control-plane/capacity/execution/architecture/contributions/shared-proposal-context.test.ts testName: "includes exact accepted scope for Git-only work without general content authority" + api.golden.shared-acting-proposal-context: + kind: vitestCase + ownerPackage: "@treeseed/api" + testFile: tests/unit/control-plane/capacity/execution/architecture/contributions/shared-proposal-context.test.ts + testName: "retains shared exact proposal context for acting and reviewing without importing peer workspace references" + api.golden.shared-acting-proposal-context-native: + kind: vitestCase + ownerPackage: "@treeseed/api" + testFile: tests/unit/control-plane/capacity/execution/architecture/contributions/proposal-source-context-native.test.ts + testName: "carries shared objective discussion and exact Git evidence into fresh TreeDX acting and review grants without changing output custody" api.golden.reviewed-predecessor-read-scope: kind: vitestCase ownerPackage: "@treeseed/api" diff --git a/src/api/capacity/services/build/ready-execution-node.ts b/src/api/capacity/services/build/ready-execution-node.ts index aedbabbdf..76fa53437 100644 --- a/src/api/capacity/services/build/ready-execution-node.ts +++ b/src/api/capacity/services/build/ready-execution-node.ts @@ -36,9 +36,12 @@ const array = (value: unknown): unknown[] => { }; const text = (...values: unknown[]): string => values.map((value) => typeof value === 'string' ? value.trim() : '').find(Boolean) ?? ''; const exactCommit = (...values: unknown[]): string => values.map(text).find((value) => /^[a-f0-9]{40}$/u.test(value)) ?? ''; -const proposalContextRefs = (proposal: Row) => [ +const sharedProposalContextRefs = (proposal: Row) => [ ...array(proposal.objectiveRefs), ...array(proposal.evidenceRefs), ...(proposal.discussionRef ? [proposal.discussionRef] : []), +]; +const proposalContextRefs = (proposal: Row) => [ + ...sharedProposalContextRefs(proposal), ...array(record(proposal.executionPlan).workItems).flatMap(item => array(record(item).contextRefs)), ]; const stable = (value: unknown): string => { @@ -244,7 +247,9 @@ export async function workItemContext(store: any, node: ExecutionNode): Promise< const workItems = array(record(exact.definition.executionPlan).workItems).map(record); const workItem = workItems.find((candidate) => text(candidate.id) === node.workItemId); if (!workItem) throw new CapacityGovernanceError('execution_node_work_item_missing', `Node ${node.id} work item is missing.`, 409); - return canonicalProposalContextRefs(store, { ...node, projectId: sourceProjectId }, array(workItem.contextRefs)); + return canonicalProposalContextRefs(store, { ...node, projectId: sourceProjectId }, [ + ...array(workItem.contextRefs), ...sharedProposalContextRefs(exact.definition), + ]); } diff --git a/tests/unit/control-plane/capacity/execution/architecture/contributions/proposal-source-context-native.test.ts b/tests/unit/control-plane/capacity/execution/architecture/contributions/proposal-source-context-native.test.ts index 6b2c26603..9f80475af 100644 --- a/tests/unit/control-plane/capacity/execution/architecture/contributions/proposal-source-context-native.test.ts +++ b/tests/unit/control-plane/capacity/execution/architecture/contributions/proposal-source-context-native.test.ts @@ -1,11 +1,73 @@ import { expect, it, vi } from 'vitest'; import { proposalNativeFixture } from '../../../../governance/proposals/architecture/proposal-native-fixture.ts'; -import { readyProposal } from '../../../../governance/proposals/architecture/ready-proposal-fixture.ts'; +import { readyContributionProposal, readyProposal } from '../../../../governance/proposals/architecture/ready-proposal-fixture.ts'; import { workItemContext } from '../../../../../../../src/api/capacity/services/build/ready-execution-node.ts'; import { buildAssignmentAttempt } from '../../../../../../../src/api/capacity/services/capacity/assignments/planning/execution/assignment-attempt-builder.ts'; import { resolveKnowledgeGatewayConnection } from '../../../../../../../src/api/knowledge/gateway-treedx-connection.ts'; import { canonicalOfferBuildInput } from '../../fixtures/assignment-attempt-fixtures.ts'; import { assignmentResultSchema } from '@treeseed/sdk/agent-capacity'; +import { validatePortableContentData } from '@treeseed/sdk/content-validation'; + +it('carries shared objective discussion and exact Git evidence into fresh TreeDX acting and review grants without changing output custody', async () => { + vi.stubEnv('TREESEED_TREEDX_URL', ''); vi.stubEnv('TREESEED_TREEDX_BASE_URL', ''); vi.stubEnv('TREESEED_ENVIRONMENT', 'test'); + const f = await proposalNativeFixture(); + try { + for (const path of ['', '/objectives/escape.mdx', 'objectives/../notes/escape.mdx', 'discussion-messages/cleanup/../escape.mdx', 'discussion-messages/../../escape.mdx']) + expect(() => f.publishContent(path, { id: 'escape' })).toThrow('Unsafe fixture path'); + const objectiveFile = f.publishContent('objectives/related.mdx', { id: 'related', title: 'Source cleanup diagnostics', summary: 'Preserve retained work and unknown outcomes.' }); + const discussionFile = f.publishContent('discussion-messages/cleanup/plan.mdx', { id: 'planning', body: 'Inspect the authorized cleanup boundary before changing it.' }); + const objective = { store: 'treedx' as const, model: 'objective', id: 'related', repository: 'repository', commit: objectiveFile.commit, path: 'objectives/related.mdx' }; + const discussion = { ...objective, model: 'discussion-message', id: 'planning', commit: discussionFile.commit, path: 'discussion-messages/cleanup/plan.mdx' }; + const source = { store: 'git' as const, model: 'repository', id: 'software-source', repository: 'treeseed-ai/project', commit: 'c'.repeat(40) }; + const peer = { ...source, id: 'peer-workspace', repository: 'treeseed-ai/peer', commit: 'd'.repeat(40) }; + const workspace = { store: 'treedx' as const, model: 'repository', id: 'repository', repository: 'repository', commit: objectiveFile.commit }; + const definition = readyContributionProposal(), item = definition.executionPlan.workItems[0]!; + Object.assign(definition, { objectiveRefs: [objective], evidenceRefs: [source], discussionRef: discussion, + executionPlan: { workItems: [{ ...item, workspace: 'treedx', contextRefs: [workspace], requestedPermissions: { + content: { read: ['objective', 'discussion-message'], write: ['objective'] }, tools: ['source.read'] } }, + { ...item, id: 'peer-contribution', contextRefs: [peer] }] } }); + expect(validatePortableContentData('proposal', definition).diagnostics).toEqual([]); + const frozen = await f.publish(definition), proposalRef = { store: 'treedx' as const, model: 'proposal', id: 'proposal', revision: 1, + repository: 'repository', commit: frozen.commit, path: 'proposals/proposal.mdx', digest: `sha256:${frozen.digest}` }; + const store = { ...f.store, getGovernanceProposal: async () => { + const row = await f.store.first("SELECT * FROM governance_proposals WHERE id='proposal'"); + return row ? { ...row, teamId: row.team_id, projectId: row.project_id } : null; + } }; + const permissions = { content: { read: ['agent', 'proposal', 'decision', 'objective', 'discussion-message'], write: ['objective'] }, tools: ['source.read'] }; + const definitionFile = f.publishContent('agents/context-author.mdx', { schemaVersion: 'treeseed.agent/v1', id: 'configured/context-author', + name: 'Context author', agentClass: 'configured-author', purpose: 'Produce the accepted cleanup contract.', responsibilities: ['Read exact accepted context.'], + capabilities: ['architecture-planning'], context: { include: ['assignment-subject'] }, activityProfiles: { + acting: { handler: 'writer', permissions, prompt: { system: 'Produce the accepted contract without changing source.' } }, + reviewing: { handler: 'writer', permissions, prompt: { system: 'Review the exact accepted contract.' } } } }); + const profileRef = { store: 'treedx' as const, model: 'agent', id: 'configured/context-author', repository: 'repository', commit: definitionFile.commit, path: 'agents/context-author.mdx' }; + const held = await f.snapshot(); + for (const kind of ['acting', 'reviewing'] as const) { + const input = structuredClone(canonicalOfferBuildInput()), candidate = input.candidate; + Object.assign(candidate.node, { kind, pairRole: kind === 'acting' ? 'actor' : 'reviewer', sourceRef: proposalRef, workItemId: item.id, workspace: 'treedx', requestedPermissions: permissions }); + candidate.effectiveProfile = { ...candidate.effectiveProfile, activity: kind, profileRef, handler: 'writer', permissionCeiling: structuredClone(permissions) } as never; + candidate.projectContentRepositoryId = 'repository'; candidate.sourceRepositories = [source.repository]; + const refs = await workItemContext(store, candidate.node); + expect(refs).toEqual([workspace, objective, source, discussion]); expect(refs).not.toContainEqual(peer); + candidate.contextRefs = [proposalRef, ...refs]; + const before = structuredClone(input), issued = buildAssignmentAttempt(input).assignment; + expect(issued.contextRefs).toContainEqual(source); expect(issued.contextRefs).not.toContainEqual(peer); + expect(issued.grant.sourceRead).toEqual([source.repository]); expect(issued.grant.sourceWrite).toEqual([]); + expect(issued.grant.tools).toEqual(['source.read']); expect(issued.workspace.mode).toBe('treedx'); + expect(issued.grant.contentWrite).toHaveLength(1); + expect(issued.grant.contentWrite[0]).toMatchObject({ repository: 'repository', commit: frozen.commit, model: 'objective' }); + const denied = structuredClone(input); + denied.candidate.effectiveProfile.permissionCeiling.content.read = ['agent', 'proposal', 'decision', 'objective']; + expect(() => buildAssignmentAttempt(denied)).toThrow('Ready node requests authority outside its effective activity profile.'); + for (const [reference, file] of [[objective, objectiveFile], [discussion, discussionFile], [profileRef, definitionFile]] as const) { + expect(issued.grant.contentRead).toContainEqual(reference); + const connection = await resolveKnowledgeGatewayConnection(f.store, { projectId: 'project', write: false, relationPaths: true, readRefs: [reference.commit] }); + const observed = await connection!.client.readRepositoryFile({ repoId: reference.repository, ref: reference.commit, path: reference.path, encoding: 'utf8', parseFrontmatter: true, allowProtected: true }) as { resolvedRef: string; file: { content: string } }; + expect(observed.resolvedRef).toBe(reference.commit); expect(observed.file.content).toBe(file.source); + } + expect(input).toEqual(before); expect(await f.snapshot()).toEqual(held); + } + } finally { await f.close(); vi.unstubAllEnvs(); } +}); // Committed native Git, original SQL and the official HTTP reader; configured // nodes are controlled inputs. No model execution or authenticated grant claim. diff --git a/tests/unit/control-plane/governance/proposals/architecture/proposal-native-fixture.ts b/tests/unit/control-plane/governance/proposals/architecture/proposal-native-fixture.ts index 6e1505506..28538372e 100644 --- a/tests/unit/control-plane/governance/proposals/architecture/proposal-native-fixture.ts +++ b/tests/unit/control-plane/governance/proposals/architecture/proposal-native-fixture.ts @@ -3,12 +3,12 @@ import { execFileSync } from 'node:child_process'; import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; import { createServer } from 'node:http'; import { tmpdir } from 'node:os'; -import { join } from 'node:path'; +import { dirname, join } from 'node:path'; import { isolatedPostgres } from '../../../fixtures/isolated-postgres.ts'; import { parse, stringify } from 'yaml'; import { splitPostgresSqlStatements } from '../../../../../../src/api/persistence/postgres-sql-statements.ts'; -const fixturePath = (path: string) => /^(proposals|decisions|agents|notes)\/[a-z0-9-]+\.mdx$/u.test(path); +const fixturePath = (path: string) => /^(?:(?:proposals|decisions|agents|notes|objectives)\/[a-z0-9-]+|discussion-messages\/[a-z0-9-]+\/[a-z0-9-]+)\.mdx$/u.test(path); /** Real owning SQL + official HTTP client + committed native Git bytes. * The remote files/read endpoint and library binding are isolated fixtures, @@ -62,7 +62,7 @@ export async function proposalNativeFixture() { all: async (sql: string, parameters: unknown[] = []) => (await query(sql, parameters)).rows }; const publishContent = (path: string, definition: Record) => { if (!fixturePath(path)) throw new Error('Unsafe fixture path'); - mkdirSync(join(root, path.split('/')[0]!), { recursive: true }); + mkdirSync(dirname(join(root, path)), { recursive: true }); const source = `---\n${stringify(definition)}---\n`; writeFileSync(join(root, path), source); git('add', path); git('commit', '--quiet', '--allow-empty', '-m', 'Governed fixture input');