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 @@ -1611,6 +1611,12 @@ workflow:
- id: accepted-unissued-fixture-parent
action: { verifier: api.golden.accepted-unissued-fixture-parent }
expect: { status: passed }
- id: closed-workday-source-condition
action: { verifier: api.golden.closed-workday-source-condition }
expect: { status: passed }
- id: closed-workday-authority-denials
action: { verifier: api.golden.closed-workday-authority-denials }
expect: { status: passed }
- id: architecture-living-graph-sql-1
action: { verifier: api.golden.architecture-living-graph-sql-1 }
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 @@ -2841,6 +2841,16 @@ verifiers:
ownerPackage: "@treeseed/api"
testFile: tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-unissued-fixture.test.ts
testName: "retains a real closed Workday parent for the native unissued Decision handoff and its public observation"
api.golden.closed-workday-source-condition:
kind: vitestCase
ownerPackage: "@treeseed/api"
testFile: tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts
testName: "re-evaluates Decision conditions after a selected workday closes before acting admission"
api.golden.closed-workday-authority-denials:
kind: vitestCase
ownerPackage: "@treeseed/api"
testFile: tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts
testName: "does not retain completed authority when current Decision or feedback blocks it"
api.golden.architecture-living-graph-sql-1:
kind: vitestCase
ownerPackage: "@treeseed/api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export function applyOperationalState(current: TeamGraph, projected: TeamGraph,
const terminalProjectionNodeIds = new Set<string>();
const nodes = projected.nodes.map((node) => {
const prior = priorById.get(node.id);
// A terminal simulation no longer owns this decision projection. Retire its
// candidate and review state; a later selected workday gets a fresh attempt.
if (prior?.workdayId && !node.workdayId && node.authorityRefs?.some((reference) => reference.model === 'decision')) {
// Retire terminal simulation workloads, not source-derived conditions.
// Current authority and feedback must remain evaluable before a fresh start.
if (node.kind !== 'condition' && prior?.workdayId && !node.workdayId
&& node.authorityRefs?.some((reference) => reference.model === 'decision')) {
// Approval may follow estimation closeout. Refresh only never-issued
// candidates that have not yet received Decision authority; preflight
// must still select the new workday before any execution is admissible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,36 @@ it('does not manufacture Decision authority before approval', () => {
const result = graphNode(applyOperationalState(current, projected, 4), 'first', 'actor');
expect(result.status).toBe('proposed'); expect(result.authorityRefs?.some(ref => ref.model === 'decision')).toBe(false);
});

it('re-evaluates Decision conditions after a selected workday closes before acting admission', () => {
for (const priorStatus of ['completed', 'stale'] as const) for (const issued of [true, false]) {
const projected = graphState(graphProjection()), current = structuredClone(projected);
const condition = current.nodes.find(node => node.condition?.conditionType === 'authority')!;
Object.assign(condition, { workdayId: 'closed-before-acting', status: priorStatus, nodeRevision: 3 });
const actor = graphNode(current, 'first', 'actor');
Object.assign(actor, { workdayId: 'closed-before-acting', status: 'stale', nodeRevision: 3 });
const held = structuredClone({ current, projected });
const next = applyOperationalState(current, projected, 4, new Set(), new Map(), new Map(), new Set(issued ? [actor.id] : []));
const resolved = next.nodes.find(node => node.id === condition.id)!;
expect(resolved).toEqual({ ...projected.nodes.find(node => node.id === condition.id), nodeRevision: 4,
graphRevisionCreated: condition.graphRevisionCreated, graphRevisionUpdated: 4 });
expect(resolved).not.toHaveProperty('workdayId');
expect(graphNode(next, 'first', 'actor')).toEqual(actor);
expect(applyOperationalState(next, projected, 5).nodes).toEqual(next.nodes);
expect({ current, projected }).toEqual(held);
}
});

it('does not retain completed authority when current Decision or feedback blocks it', () => {
for (const reason of ['not-current', 'unresolved-feedback'] as const) {
const source = graphSource(), current = graphState(graphProjection([source]));
const old = current.nodes.find(node => node.condition?.conditionType === 'authority')!;
Object.assign(old, { workdayId: 'closed-before-acting', status: 'completed', nodeRevision: 3 });
if (reason === 'not-current') source.decision!.current = false;
else source.feedback = [{ id: 'concern', kind: 'concern', resolved: false, sourceRef: old.sourceRef }];
const projected = graphState(graphProjection([source]));
const next = applyOperationalState(current, projected, 4), condition = next.nodes.find(node => node.id === old.id)!;
expect(condition.status).toBe('blocked'); expect(condition).not.toHaveProperty('workdayId');
expect(graphNode(next, 'first', 'actor').status).not.toBe('ready');
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ export async function verifyNativeUnissuedDecisionHandoff(f: Awaited<ReturnType<
expect(receipt.selectedDemands).toEqual([expect.objectContaining({ sourceType: 'execution-node', sourceId: actor.id,
actingAuthority: expect.objectContaining({ decisionId, executionNodeId: actor.id, executionNodeRevision: refreshed.nodeRevision + 1 }) })]);
expect(await service.show(f.principal, 'team', {})).toEqual(before);
// Controlled projection from a selected simulation closed BEFORE any acting
// attempt. Keep the genuinely published Decision and all estimates unchanged.
const condition = before.nodes.find(node => node.sourceRef.id === proposalId && node.condition?.conditionType === 'authority');
assert.ok(condition); expect(condition.status).toBe('completed');
const parentBefore = await f.store.first('SELECT * FROM capacity_workday_runs WHERE id=?', [closedWorkdayId]);
await f.query("UPDATE execution_nodes SET workday_id=?,status='stale' WHERE id IN (?,?)",
[closedWorkdayId, actor.id, condition.id]);
const retiredActor = await service.node(f.principal, 'team', actor.id);
const closedPreview = await reconcileExecutionGraph(f.store, 'team', { plan: true });
assert.ok('changes' in closedPreview); expect(closedPreview.changes.changed).toContain(condition.id);
expect((await service.node(f.principal, 'team', condition.id)).status).toBe('stale');
await Promise.all([reconcileExecutionGraph(f.store, 'team'), reconcileExecutionGraph(f.peerStore!, 'team')]);
expect(await service.node(f.principal, 'team', actor.id)).toEqual(retiredActor);
const restored = await service.node(f.principal, 'team', condition.id);
expect(restored).toMatchObject({ id: condition.id, status: 'completed', authorityRefs: condition.authorityRefs });
expect(restored).not.toHaveProperty('workdayId');
const restoredGraph = await service.show(f.principal, 'team', {});
await reconcileExecutionGraph(f.store, 'team'); expect(await service.show(f.principal, 'team', {})).toEqual(restoredGraph);
const restarted = await createWorkdayService(createCapacityControlPlane(f.store)).preflight(f.principal, 'team',
{ ...intent, startsAt: new Date().toISOString(), allocation: { planningPercent: 0 } });
expect(restarted.selectedDemands).toEqual([expect.objectContaining({ sourceId: actor.id, mode: 'acting',
actingAuthority: expect.objectContaining({ decisionId, executionNodeId: actor.id, executionNodeRevision: retiredActor.nodeRevision + 1 }) })]);
expect(await service.show(f.principal, 'team', {})).toEqual(restoredGraph);
expect(await f.store.first('SELECT * FROM capacity_workday_runs WHERE id=?', [closedWorkdayId])).toEqual(parentBefore);
expect({ assignments: await f.store.all('SELECT * FROM capacity_provider_assignments ORDER BY id'),
decisions: await f.store.all('SELECT * FROM governance_decisions ORDER BY id'),
usage: await f.store.all('SELECT * FROM capacity_usage_actuals ORDER BY id'),
Expand Down
Loading