Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 10 additions & 0 deletions guarantees/verifiers/golden.verifiers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions src/api/capacity/services/build/ready-execution-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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),
]);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string, unknown>) => {
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');
Expand Down
Loading