-
Notifications
You must be signed in to change notification settings - Fork 0
feat(planning): enforce durable task completion chronology #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
17
commits into
main
Choose a base branch
from
feat/planning-task-completion-chronology-v1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fe6e6a7
test(planning): require durable task completion chronology
seonghobae a880b96
ci(planning): prove task chronology migration RED
seonghobae 86d6714
feat(planning): enforce task completion chronology
seonghobae 01b5d40
test(planning): verify completion chronology in PostgreSQL
seonghobae 2657463
ci(planning): exercise chronology constraint in PostgreSQL
seonghobae 856af24
test(planning): make completion migration assertion formatting-agnostic
seonghobae 4f462b0
chore(planning): retire completion chronology canary
seonghobae 655088b
test(planning): remove dynamic SQL from chronology contract
seonghobae 164ae03
test(planning): require staged completion constraint validation
seonghobae 4b76a04
test(planning): run staged chronology reality canary
seonghobae 45b7c59
fix(planning): stage task completion chronology constraint
seonghobae a858ded
fix(planning): validate staged task completion chronology
seonghobae 543d156
docs(planning): document staged chronology migration boundary
seonghobae 1de871e
chore(planning): retire staged chronology canary
seonghobae 28312d5
ci(planning): repair stale PostgreSQL migration fixtures
seonghobae 9ab372e
ci(planning): execute PostgreSQL fixture chain repair
seonghobae b327e01
test(planning): keep PostgreSQL fixtures on current migrations
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
apps/planning-service/migrations/0005_task_completion_chronology.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ALTER TABLE planning.tasks | ||
| ADD CONSTRAINT tasks_completion_state_check | ||
| CHECK ( | ||
| (status = 'todo' AND completed_at IS NULL) | ||
| OR ( | ||
| status = 'done' | ||
| AND completed_at IS NOT NULL | ||
| AND completed_at >= created_at | ||
| ) | ||
| ) NOT VALID; |
2 changes: 2 additions & 0 deletions
2
apps/planning-service/migrations/0006_validate_task_completion_chronology.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ALTER TABLE planning.tasks | ||
| VALIDATE CONSTRAINT tasks_completion_state_check; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
apps/planning-service/src/task-completion-chronology-migration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import { readFile } from 'node:fs/promises'; | ||
| import { resolve } from 'node:path'; | ||
| import { Pool } from 'pg'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| const stagingMigrationPath = resolve( | ||
| __dirname, | ||
| '../migrations/0005_task_completion_chronology.sql', | ||
| ); | ||
| const validationMigrationPath = resolve( | ||
| __dirname, | ||
| '../migrations/0006_validate_task_completion_chronology.sql', | ||
| ); | ||
|
|
||
| async function readMigration(path: string): Promise<string> { | ||
| return await readFile(path, 'utf8'); | ||
| } | ||
|
|
||
| function normalizeSql(source: string): string { | ||
| return source.replace(/\s+/g, ' ').trim(); | ||
| } | ||
|
|
||
| describe('Planning task completion chronology migration', () => { | ||
| it('stages the coherent completion-state constraint before scanning historical rows', async () => { | ||
| const migration = normalizeSql(await readMigration(stagingMigrationPath)); | ||
|
|
||
| expect(migration).toContain('tasks_completion_state_check'); | ||
| expect(migration).toContain("status = 'todo' AND completed_at IS NULL"); | ||
| expect(migration).toContain("status = 'done' AND completed_at IS NOT NULL"); | ||
| expect(migration).toContain('completed_at >= created_at'); | ||
| expect(migration).toContain('NOT VALID'); | ||
| expect(migration).not.toContain('VALIDATE CONSTRAINT'); | ||
| }); | ||
|
|
||
| it('validates the staged constraint in a later migration boundary', async () => { | ||
| const migration = normalizeSql(await readMigration(validationMigrationPath)); | ||
|
|
||
| expect(migration).toContain( | ||
| 'VALIDATE CONSTRAINT tasks_completion_state_check', | ||
| ); | ||
| expect(migration).not.toContain('ADD CONSTRAINT'); | ||
| }); | ||
|
|
||
| const databaseUrl = process.env.PLANNING_DATABASE_URL; | ||
| const databaseIt = databaseUrl ? it : it.skip; | ||
|
|
||
| databaseIt( | ||
| 'rejects contradictory new task states and finishes with validated historical chronology', | ||
| async () => { | ||
| const pool = new Pool({ connectionString: databaseUrl }); | ||
|
|
||
| try { | ||
| await pool.query( | ||
| 'DROP SCHEMA IF EXISTS planning_task_completion_chronology_test CASCADE', | ||
| ); | ||
| await pool.query( | ||
| 'CREATE SCHEMA planning_task_completion_chronology_test', | ||
| ); | ||
| await pool.query( | ||
| "CREATE TABLE planning_task_completion_chronology_test.tasks (status text NOT NULL CHECK (status IN ('todo', 'done')), created_at timestamptz NOT NULL, completed_at timestamptz)", | ||
| ); | ||
|
|
||
| const stagingMigration = ( | ||
| await readMigration(stagingMigrationPath) | ||
| ).replaceAll( | ||
| 'planning.tasks', | ||
| 'planning_task_completion_chronology_test.tasks', | ||
| ); | ||
| await pool.query(stagingMigration); | ||
|
|
||
| await expect( | ||
| pool.query( | ||
| "INSERT INTO planning_task_completion_chronology_test.tasks (status, created_at, completed_at) VALUES ('todo', $1, NULL)", | ||
| ['2026-09-10T10:00:00.000Z'], | ||
| ), | ||
| ).resolves.toBeDefined(); | ||
| await expect( | ||
| pool.query( | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "INSERT INTO planning_task_completion_chronology_test.tasks (status, created_at, completed_at) VALUES ('done', $1, $2)", | ||
| ['2026-09-10T10:00:00.000Z', '2026-09-10T10:05:00.000Z'], | ||
| ), | ||
| ).resolves.toBeDefined(); | ||
| await expect( | ||
| pool.query( | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "INSERT INTO planning_task_completion_chronology_test.tasks (status, created_at, completed_at) VALUES ('todo', $1, $2)", | ||
| ['2026-09-10T10:00:00.000Z', '2026-09-10T10:05:00.000Z'], | ||
| ), | ||
| ).rejects.toMatchObject({ code: '23514' }); | ||
| await expect( | ||
| pool.query( | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "INSERT INTO planning_task_completion_chronology_test.tasks (status, created_at, completed_at) VALUES ('done', $1, NULL)", | ||
| ['2026-09-10T10:00:00.000Z'], | ||
| ), | ||
| ).rejects.toMatchObject({ code: '23514' }); | ||
| await expect( | ||
| pool.query( | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| "INSERT INTO planning_task_completion_chronology_test.tasks (status, created_at, completed_at) VALUES ('done', $1, $2)", | ||
| ['2026-09-10T10:05:00.000Z', '2026-09-10T10:00:00.000Z'], | ||
| ), | ||
| ).rejects.toMatchObject({ code: '23514' }); | ||
|
|
||
| const validationMigration = ( | ||
| await readMigration(validationMigrationPath) | ||
| ).replaceAll( | ||
| 'planning.tasks', | ||
| 'planning_task_completion_chronology_test.tasks', | ||
| ); | ||
| await pool.query(validationMigration); | ||
| const validationState = await pool.query<{ convalidated: boolean }>( | ||
| "SELECT convalidated FROM pg_constraint WHERE conname = 'tasks_completion_state_check' AND conrelid = 'planning_task_completion_chronology_test.tasks'::regclass", | ||
| ); | ||
|
|
||
| expect(validationState.rows).toEqual([{ convalidated: true }]); | ||
| } finally { | ||
| await pool.query( | ||
| 'DROP SCHEMA IF EXISTS planning_task_completion_chronology_test CASCADE', | ||
| ); | ||
| await pool.end(); | ||
| } | ||
| }, | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.