Skip to content
Draft
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
4 changes: 4 additions & 0 deletions web/__tests__/project-root-reconciliation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ describe('project-root expansion reconciliation boundary', () => {
expect(migration).toContain('CREATE CONSTRAINT TRIGGER project_root_reconciliation_write_contexts_commit_v1')
expect(migration).toContain('DEFERRABLE INITIALLY DEFERRED')
expect(migration).toContain('project-root write context must complete before commit')
expect(migration).toContain('forge.lock_project_root_reconciliation_authority_v1')
expect(migration).toContain('approval_row.project_id=p_project_id ORDER BY approval_row.id FOR UPDATE')
expect(migration).toContain('decision_row.project_id=p_project_id ORDER BY decision_row.id FOR UPDATE')
expect(migration).toContain('project-root authority lock has no active write context')
})

it('uses the dedicated login with only canonical helper state columns and fixed routines', () => {
Expand Down
12 changes: 12 additions & 0 deletions web/db/migrations/0027_epic_172_s4_packet_context.sql
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,18 @@ REVOKE ALL ON FUNCTION forge.assert_project_root_reconciliation_write_context_co
REVOKE ALL ON FUNCTION forge.reject_project_root_reconciliation_write_context_mutation_v1() FROM PUBLIC;
REVOKE ALL ON FUNCTION forge.enter_project_root_reconciliation_generation_v1(uuid,uuid,bigint,uuid) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION forge.enter_project_root_reconciliation_generation_v1(uuid,uuid,bigint,uuid) TO forge_project_root_reconciler;
CREATE OR REPLACE FUNCTION forge.lock_project_root_reconciliation_authority_v1(p_operation_id uuid, p_actor_id uuid, p_generation bigint, p_project_id uuid)
RETURNS void LANGUAGE plpgsql SECURITY DEFINER SET search_path = pg_catalog, public AS $$
BEGIN
PERFORM forge.assert_project_root_reconciler_v1();
IF NOT EXISTS (SELECT 1 FROM public.project_root_reconciliation_write_contexts context_row WHERE context_row.operation_id=p_operation_id AND context_row.actor_id=p_actor_id AND context_row.generation=p_generation AND context_row.project_id=p_project_id AND context_row.backend_pid=pg_catalog.pg_backend_pid() AND context_row.transaction_id=pg_catalog.txid_current() AND context_row.completed_at IS NULL) THEN RAISE EXCEPTION 'project-root authority lock has no active write context' USING ERRCODE='42501'; END IF;
PERFORM 1 FROM public.filesystem_mcp_grant_approvals approval_row WHERE approval_row.project_id=p_project_id ORDER BY approval_row.id FOR UPDATE;
PERFORM 1 FROM public.project_filesystem_grant_decisions decision_row WHERE decision_row.project_id=p_project_id ORDER BY decision_row.id FOR UPDATE;
PERFORM 1 FROM public.project_filesystem_current_decision_pointers pointer_row WHERE pointer_row.project_id=p_project_id FOR UPDATE;
PERFORM 1 FROM public.filesystem_mcp_current_decision_pointers pointer_row JOIN public.work_packages package_row ON package_row.id=pointer_row.work_package_id JOIN public.tasks task_row ON task_row.id=package_row.task_id WHERE task_row.project_id=p_project_id ORDER BY pointer_row.work_package_id FOR UPDATE;
END; $$;
REVOKE ALL ON FUNCTION forge.lock_project_root_reconciliation_authority_v1(uuid,uuid,bigint,uuid) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION forge.lock_project_root_reconciliation_authority_v1(uuid,uuid,bigint,uuid) TO forge_project_root_reconciler;
CREATE OR REPLACE FUNCTION forge.complete_project_root_reconciliation_generation_v1(p_operation_id uuid, p_actor_id uuid, p_generation bigint, p_project_id uuid, p_outcome text)
RETURNS TABLE(state text, last_processed_generation bigint)
LANGUAGE plpgsql
Expand Down
Loading