qualia-framework 3.4.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/tests/runner.js CHANGED
@@ -814,6 +814,225 @@ waves: 1
814
814
  fs.rmSync(tmpDir, { recursive: true, force: true });
815
815
  }
816
816
  });
817
+
818
+ // ─── v3.4.2: init guard ────────────────────────────────
819
+ it("init refuses to clobber an existing project (no --force)", () => {
820
+ const tmpDir = makeProject();
821
+ try {
822
+ const r = spawnSync(process.execPath, [
823
+ path.join(BIN, "state.js"), "init",
824
+ "--project", "TestProject",
825
+ "--phases", '[{"name":"X","goal":"Y"}]',
826
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
827
+ assert.equal(r.status, 1);
828
+ const out = JSON.parse(r.stdout);
829
+ assert.equal(out.error, "ALREADY_INITIALIZED");
830
+ } finally {
831
+ fs.rmSync(tmpDir, { recursive: true, force: true });
832
+ }
833
+ });
834
+
835
+ it("init --force overwrites an existing project (preserves lifetime)", () => {
836
+ const tmpDir = makeProject();
837
+ try {
838
+ // Seed lifetime via close-milestone first
839
+ const c = spawnSync(process.execPath, [
840
+ path.join(BIN, "state.js"), "close-milestone",
841
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
842
+ assert.equal(c.status, 0);
843
+ const tBefore = JSON.parse(fs.readFileSync(path.join(tmpDir, ".planning", "tracking.json"), "utf8"));
844
+ assert.ok(tBefore.lifetime.milestones_completed >= 1);
845
+
846
+ const r = spawnSync(process.execPath, [
847
+ path.join(BIN, "state.js"), "init",
848
+ "--project", "TestProject",
849
+ "--phases", '[{"name":"NewFoundation","goal":"X"}]',
850
+ "--force",
851
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
852
+ assert.equal(r.status, 0);
853
+ const tAfter = JSON.parse(fs.readFileSync(path.join(tmpDir, ".planning", "tracking.json"), "utf8"));
854
+ assert.equal(tAfter.lifetime.milestones_completed, tBefore.lifetime.milestones_completed);
855
+ assert.equal(tAfter.phase, 1);
856
+ assert.equal(tAfter.status, "setup");
857
+ } finally {
858
+ fs.rmSync(tmpDir, { recursive: true, force: true });
859
+ }
860
+ });
861
+
862
+ // ─── v3.4.2: close-milestone idempotency ───────────────
863
+ it("close-milestone refuses double-close (idempotency)", () => {
864
+ const tmpDir = makeProject();
865
+ try {
866
+ const r1 = spawnSync(process.execPath, [
867
+ path.join(BIN, "state.js"), "close-milestone",
868
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
869
+ assert.equal(r1.status, 0);
870
+ const out1 = JSON.parse(r1.stdout);
871
+ assert.equal(out1.lifetime.milestones_completed, 1);
872
+
873
+ // Manually rewind milestone counter to simulate a re-run on the same closed milestone.
874
+ // (Real close-milestone advances t.milestone, so a true double-close requires
875
+ // putting milestone back to its prior value.)
876
+ const tFile = path.join(tmpDir, ".planning", "tracking.json");
877
+ const t = JSON.parse(fs.readFileSync(tFile, "utf8"));
878
+ t.milestone = out1.closed_milestone; // rewind
879
+ fs.writeFileSync(tFile, JSON.stringify(t, null, 2) + "\n");
880
+
881
+ const r2 = spawnSync(process.execPath, [
882
+ path.join(BIN, "state.js"), "close-milestone",
883
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
884
+ assert.equal(r2.status, 1);
885
+ const out2 = JSON.parse(r2.stdout);
886
+ assert.equal(out2.error, "ALREADY_CLOSED");
887
+ } finally {
888
+ fs.rmSync(tmpDir, { recursive: true, force: true });
889
+ }
890
+ });
891
+
892
+ it("close-milestone --force allows re-close", () => {
893
+ const tmpDir = makeProject();
894
+ try {
895
+ const r1 = spawnSync(process.execPath, [
896
+ path.join(BIN, "state.js"), "close-milestone",
897
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
898
+ assert.equal(r1.status, 0);
899
+
900
+ const tFile = path.join(tmpDir, ".planning", "tracking.json");
901
+ const t = JSON.parse(fs.readFileSync(tFile, "utf8"));
902
+ t.milestone = JSON.parse(r1.stdout).closed_milestone;
903
+ fs.writeFileSync(tFile, JSON.stringify(t, null, 2) + "\n");
904
+
905
+ const r2 = spawnSync(process.execPath, [
906
+ path.join(BIN, "state.js"), "close-milestone", "--force",
907
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
908
+ assert.equal(r2.status, 0);
909
+ const out2 = JSON.parse(r2.stdout);
910
+ assert.equal(out2.lifetime.milestones_completed, 2);
911
+ } finally {
912
+ fs.rmSync(tmpDir, { recursive: true, force: true });
913
+ }
914
+ });
915
+
916
+ // ─── v3.4.2: backfill never reduces lifetime (Math.max) ─
917
+ it("backfill-lifetime never reduces existing counters", () => {
918
+ const tmpDir = makeProject();
919
+ try {
920
+ // Seed lifetime with high values (simulating prior close-milestone)
921
+ const tFile = path.join(tmpDir, ".planning", "tracking.json");
922
+ const t = JSON.parse(fs.readFileSync(tFile, "utf8"));
923
+ t.lifetime.tasks_completed = 100;
924
+ t.lifetime.phases_completed = 20;
925
+ fs.writeFileSync(tFile, JSON.stringify(t, null, 2) + "\n");
926
+
927
+ // Backfill on a project with NO completed phases would compute 0/0
928
+ const r = spawnSync(process.execPath, [
929
+ path.join(BIN, "state.js"), "backfill-lifetime",
930
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
931
+ assert.equal(r.status, 0);
932
+ const tAfter = JSON.parse(fs.readFileSync(tFile, "utf8"));
933
+ assert.equal(tAfter.lifetime.tasks_completed, 100, "backfill must NOT reduce tasks_completed");
934
+ assert.equal(tAfter.lifetime.phases_completed, 20, "backfill must NOT reduce phases_completed");
935
+ } finally {
936
+ fs.rmSync(tmpDir, { recursive: true, force: true });
937
+ }
938
+ });
939
+
940
+ // ─── v3.4.2: atomic write leaves no .tmp file ──────────
941
+ it("transition leaves no .tmp file on success (atomic write)", () => {
942
+ const tmpDir = makeProject();
943
+ try {
944
+ makeValidPlan(tmpDir, 1);
945
+ const r = runState(["transition", "--to", "planned"], tmpDir);
946
+ assert.equal(r.status, 0);
947
+ const planning = path.join(tmpDir, ".planning");
948
+ const tmps = fs.readdirSync(planning).filter(f => f.includes(".tmp."));
949
+ assert.equal(tmps.length, 0, `Stale .tmp files: ${tmps.join(", ")}`);
950
+ } finally {
951
+ fs.rmSync(tmpDir, { recursive: true, force: true });
952
+ }
953
+ });
954
+
955
+ // ─── v3.6.0: tracking.json schema additions ────────────
956
+ it("init writes new schema fields (team_id, project_id, build_count, etc.)", () => {
957
+ const tmpDir = makeProject();
958
+ try {
959
+ const t = JSON.parse(fs.readFileSync(path.join(tmpDir, ".planning", "tracking.json"), "utf8"));
960
+ // New v3.6 fields (default to empty / 0, but must be present)
961
+ assert.ok("team_id" in t, "team_id missing");
962
+ assert.ok("project_id" in t, "project_id missing");
963
+ assert.ok("git_remote" in t, "git_remote missing");
964
+ assert.ok("session_started_at" in t, "session_started_at missing");
965
+ assert.ok("last_pushed_at" in t, "last_pushed_at missing");
966
+ assert.ok("build_count" in t, "build_count missing");
967
+ assert.ok("deploy_count" in t, "deploy_count missing");
968
+ assert.ok("submitted_by" in t, "submitted_by missing");
969
+ assert.ok("last_closed_milestone" in t.lifetime, "lifetime.last_closed_milestone missing");
970
+ } finally {
971
+ fs.rmSync(tmpDir, { recursive: true, force: true });
972
+ }
973
+ });
974
+
975
+ it("init --force defensively hydrates partial lifetime (no NaN)", () => {
976
+ const tmpDir = makeProject();
977
+ try {
978
+ // Write a partial lifetime that's missing keys
979
+ const tFile = path.join(tmpDir, ".planning", "tracking.json");
980
+ const t = JSON.parse(fs.readFileSync(tFile, "utf8"));
981
+ t.lifetime = { tasks_completed: 5 }; // partial — missing other keys
982
+ fs.writeFileSync(tFile, JSON.stringify(t, null, 2) + "\n");
983
+
984
+ const r = spawnSync(process.execPath, [
985
+ path.join(BIN, "state.js"), "init",
986
+ "--project", "TestProject",
987
+ "--phases", '[{"name":"X","goal":"Y"}]',
988
+ "--force",
989
+ ], { encoding: "utf8", cwd: tmpDir, timeout: 5000, stdio: ["pipe", "pipe", "pipe"] });
990
+ assert.equal(r.status, 0);
991
+ const tAfter = JSON.parse(fs.readFileSync(tFile, "utf8"));
992
+ // Original partial value preserved
993
+ assert.equal(tAfter.lifetime.tasks_completed, 5);
994
+ // Missing keys defaulted to 0, never NaN
995
+ assert.equal(tAfter.lifetime.phases_completed, 0);
996
+ assert.equal(tAfter.lifetime.milestones_completed, 0);
997
+ assert.equal(tAfter.lifetime.total_phases, 0);
998
+ assert.equal(tAfter.lifetime.last_closed_milestone, 0);
999
+ assert.ok(!Number.isNaN(tAfter.lifetime.phases_completed));
1000
+ } finally {
1001
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1002
+ }
1003
+ });
1004
+
1005
+ // ─── v3.5.0: CRLF tolerance in parseStateMd ────────────
1006
+ it("parseStateMd tolerates CRLF line endings (Windows-edited STATE.md)", () => {
1007
+ const tmpDir = makeProject();
1008
+ try {
1009
+ const stateFile = path.join(tmpDir, ".planning", "STATE.md");
1010
+ const lf = fs.readFileSync(stateFile, "utf8");
1011
+ // Simulate Windows editor save: convert all \n to \r\n
1012
+ const crlf = lf.replace(/\n/g, "\r\n");
1013
+ fs.writeFileSync(stateFile, crlf);
1014
+ const r = runState(["check"], tmpDir);
1015
+ assert.equal(r.status, 0, `check failed on CRLF STATE.md: ${r.stdout} ${r.stderr}`);
1016
+ const out = JSON.parse(r.stdout);
1017
+ assert.equal(out.phase_name, "Foundation", "phase_name must NOT contain trailing \\r");
1018
+ assert.equal(out.status, "setup", "status must NOT contain trailing \\r");
1019
+ } finally {
1020
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1021
+ }
1022
+ });
1023
+
1024
+ // ─── v3.4.2: lock file is released after mutation ──────
1025
+ it("transition releases the .state.lock", () => {
1026
+ const tmpDir = makeProject();
1027
+ try {
1028
+ makeValidPlan(tmpDir, 1);
1029
+ runState(["transition", "--to", "planned"], tmpDir);
1030
+ const lockExists = fs.existsSync(path.join(tmpDir, ".planning", ".state.lock"));
1031
+ assert.equal(lockExists, false, "lock file should be released after transition");
1032
+ } finally {
1033
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1034
+ }
1035
+ });
817
1036
  });
818
1037
 
819
1038
  // ═══════════════════════════════════════════════════════════
@@ -912,6 +1131,53 @@ describe("Hooks", () => {
912
1131
  assert.match(content, /last_commit/);
913
1132
  });
914
1133
 
1134
+ // v3.4.2: behavioral test — the stamp must actually mutate tracking.json
1135
+ // AND create a real commit so the push includes it.
1136
+ it("pre-push.js mutates tracking.json AND commits the stamp", () => {
1137
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "qualia-push-real-"));
1138
+ try {
1139
+ // Init a real git repo
1140
+ const gitOpts = { cwd: tmpDir, encoding: "utf8", timeout: 5000, stdio: ["pipe", "pipe", "pipe"] };
1141
+ spawnSync("git", ["init", "--initial-branch=main"], gitOpts);
1142
+ spawnSync("git", ["config", "user.email", "test@example.com"], gitOpts);
1143
+ spawnSync("git", ["config", "user.name", "Test"], gitOpts);
1144
+ spawnSync("git", ["config", "commit.gpgsign", "false"], gitOpts);
1145
+
1146
+ // Seed .planning/tracking.json + an initial commit
1147
+ fs.mkdirSync(path.join(tmpDir, ".planning"));
1148
+ const tFile = path.join(tmpDir, ".planning", "tracking.json");
1149
+ fs.writeFileSync(tFile, JSON.stringify({
1150
+ project: "test", phase: 1, status: "setup", last_commit: "OLD", last_updated: "2020-01-01T00:00:00Z",
1151
+ }, null, 2) + "\n");
1152
+ spawnSync("git", ["add", "."], gitOpts);
1153
+ spawnSync("git", ["commit", "-m", "seed", "--no-verify"], gitOpts);
1154
+
1155
+ const headBefore = spawnSync("git", ["rev-parse", "HEAD"], gitOpts).stdout.trim();
1156
+
1157
+ // Run the hook
1158
+ const r = spawnSync(process.execPath, [path.join(HOOKS, "pre-push.js")], {
1159
+ encoding: "utf8", cwd: tmpDir, timeout: 10000, stdio: ["pipe", "pipe", "pipe"],
1160
+ });
1161
+ assert.equal(r.status, 0, `pre-push exited ${r.status}: ${r.stderr}`);
1162
+
1163
+ // tracking.json must have been mutated
1164
+ const t = JSON.parse(fs.readFileSync(tFile, "utf8"));
1165
+ assert.notEqual(t.last_commit, "OLD", "last_commit should have been updated");
1166
+ assert.notEqual(t.last_updated, "2020-01-01T00:00:00Z", "last_updated should have been updated");
1167
+ assert.match(t.last_updated, /^\d{4}-\d{2}-\d{2}T/);
1168
+
1169
+ // A NEW commit must exist (this is the smoking-gun fix from v3.4.2)
1170
+ const headAfter = spawnSync("git", ["rev-parse", "HEAD"], gitOpts).stdout.trim();
1171
+ assert.notEqual(headAfter, headBefore, "pre-push must commit the stamp so it ships with the push");
1172
+
1173
+ // The new commit must be authored by the bot, not the user
1174
+ const author = spawnSync("git", ["log", "-1", "--format=%an <%ae>"], gitOpts).stdout.trim();
1175
+ assert.match(author, /Qualia Framework/);
1176
+ } finally {
1177
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1178
+ }
1179
+ });
1180
+
915
1181
  it("pre-push.js exits 0 with no tracking.json", () => {
916
1182
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "qualia-push-"));
917
1183
  try {
@@ -1303,6 +1569,135 @@ describe("Hooks", () => {
1303
1569
  fs.rmSync(tmpDir, { recursive: true, force: true });
1304
1570
  }
1305
1571
  });
1572
+
1573
+ // v3.5.0: refspec bypass — EMPLOYEE on a feature branch trying to push
1574
+ // `feature/x:main` MUST be blocked, even though current branch isn't main.
1575
+ it("branch-guard: EMPLOYEE refspec push to main -> blocked", () => {
1576
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "qualia-bg-"));
1577
+ try {
1578
+ const projDir = path.join(tmpDir, "proj");
1579
+ fs.mkdirSync(projDir, { recursive: true });
1580
+ fs.mkdirSync(path.join(tmpDir, ".claude"), { recursive: true });
1581
+ spawnSync("git", ["init", "-q"], { cwd: projDir });
1582
+ spawnSync("git", ["checkout", "-b", "feature/x", "-q"], { cwd: projDir, stdio: "pipe" });
1583
+ fs.writeFileSync(path.join(tmpDir, ".claude", ".qualia-config.json"), JSON.stringify({ role: "EMPLOYEE" }));
1584
+ // Send Claude Code hook payload via stdin
1585
+ const payload = JSON.stringify({
1586
+ tool_input: { command: "git push origin feature/x:main" },
1587
+ });
1588
+ const r = spawnSync(process.execPath, [path.join(HOOKS, "branch-guard.js")], {
1589
+ encoding: "utf8", cwd: projDir, timeout: 5000,
1590
+ env: { ...process.env, HOME: tmpDir, USERPROFILE: tmpDir },
1591
+ input: payload,
1592
+ stdio: ["pipe", "pipe", "pipe"],
1593
+ });
1594
+ assert.equal(r.status, 2, "refspec push to main must be blocked for EMPLOYEE");
1595
+ } finally {
1596
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1597
+ }
1598
+ });
1599
+
1600
+ it("branch-guard: EMPLOYEE refspec push to master -> blocked", () => {
1601
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "qualia-bg-"));
1602
+ try {
1603
+ const projDir = path.join(tmpDir, "proj");
1604
+ fs.mkdirSync(projDir, { recursive: true });
1605
+ fs.mkdirSync(path.join(tmpDir, ".claude"), { recursive: true });
1606
+ spawnSync("git", ["init", "-q"], { cwd: projDir });
1607
+ spawnSync("git", ["checkout", "-b", "feature/x", "-q"], { cwd: projDir, stdio: "pipe" });
1608
+ fs.writeFileSync(path.join(tmpDir, ".claude", ".qualia-config.json"), JSON.stringify({ role: "EMPLOYEE" }));
1609
+ const payload = JSON.stringify({
1610
+ tool_input: { command: "git push origin HEAD:master" },
1611
+ });
1612
+ const r = spawnSync(process.execPath, [path.join(HOOKS, "branch-guard.js")], {
1613
+ encoding: "utf8", cwd: projDir, timeout: 5000,
1614
+ env: { ...process.env, HOME: tmpDir, USERPROFILE: tmpDir },
1615
+ input: payload,
1616
+ stdio: ["pipe", "pipe", "pipe"],
1617
+ });
1618
+ assert.equal(r.status, 2, "refspec push to master must be blocked for EMPLOYEE");
1619
+ } finally {
1620
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1621
+ }
1622
+ });
1623
+
1624
+ it("branch-guard: OWNER refspec push to main -> allowed", () => {
1625
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "qualia-bg-"));
1626
+ try {
1627
+ const projDir = path.join(tmpDir, "proj");
1628
+ fs.mkdirSync(projDir, { recursive: true });
1629
+ fs.mkdirSync(path.join(tmpDir, ".claude"), { recursive: true });
1630
+ spawnSync("git", ["init", "-q"], { cwd: projDir });
1631
+ spawnSync("git", ["checkout", "-b", "feature/x", "-q"], { cwd: projDir, stdio: "pipe" });
1632
+ fs.writeFileSync(path.join(tmpDir, ".claude", ".qualia-config.json"), JSON.stringify({ role: "OWNER" }));
1633
+ const payload = JSON.stringify({
1634
+ tool_input: { command: "git push origin feature/x:main" },
1635
+ });
1636
+ const r = spawnSync(process.execPath, [path.join(HOOKS, "branch-guard.js")], {
1637
+ encoding: "utf8", cwd: projDir, timeout: 5000,
1638
+ env: { ...process.env, HOME: tmpDir, USERPROFILE: tmpDir },
1639
+ input: payload,
1640
+ stdio: ["pipe", "pipe", "pipe"],
1641
+ });
1642
+ assert.equal(r.status, 0, "OWNER may push to main via refspec");
1643
+ } finally {
1644
+ fs.rmSync(tmpDir, { recursive: true, force: true });
1645
+ }
1646
+ });
1647
+
1648
+ // v3.5.0: migration-guard — comments stripped before pattern match
1649
+ it("migration-guard: commented-out DROP TABLE is NOT blocked", () => {
1650
+ const r = runHook("migration-guard.js", {
1651
+ tool_input: {
1652
+ file_path: "supabase/migrations/001_init.sql",
1653
+ content: "-- DROP TABLE old_users; (rolled back, kept for reference)\nCREATE TABLE foo (id uuid) WITH (security_invoker = true);\nALTER TABLE foo ENABLE ROW LEVEL SECURITY;",
1654
+ },
1655
+ });
1656
+ assert.equal(r.status, 0, `commented DROP should not block: ${r.stdout || r.stderr}`);
1657
+ });
1658
+
1659
+ // v3.5.0: migration-guard — new destructive patterns
1660
+ it("migration-guard: ALTER TABLE DROP COLUMN -> blocked", () => {
1661
+ const r = runHook("migration-guard.js", {
1662
+ tool_input: { file_path: "supabase/migrations/002.sql", content: "ALTER TABLE users DROP COLUMN ssn;" },
1663
+ });
1664
+ assert.equal(r.status, 2, "ALTER TABLE DROP COLUMN must block");
1665
+ });
1666
+
1667
+ it("migration-guard: DROP DATABASE -> blocked", () => {
1668
+ const r = runHook("migration-guard.js", {
1669
+ tool_input: { file_path: "supabase/migrations/003.sql", content: "DROP DATABASE production;" },
1670
+ });
1671
+ assert.equal(r.status, 2, "DROP DATABASE must block");
1672
+ });
1673
+
1674
+ it("migration-guard: UPDATE without WHERE -> blocked", () => {
1675
+ const r = runHook("migration-guard.js", {
1676
+ tool_input: { file_path: "supabase/migrations/004.sql", content: "UPDATE users SET email = NULL;" },
1677
+ });
1678
+ assert.equal(r.status, 2, "UPDATE without WHERE must block");
1679
+ });
1680
+
1681
+ it("migration-guard: GRANT TO PUBLIC -> blocked", () => {
1682
+ const r = runHook("migration-guard.js", {
1683
+ tool_input: { file_path: "supabase/migrations/005.sql", content: "GRANT ALL ON users TO PUBLIC;" },
1684
+ });
1685
+ assert.equal(r.status, 2, "GRANT TO PUBLIC must block");
1686
+ });
1687
+
1688
+ it("migration-guard: CREATE TEMP TABLE without RLS -> NOT blocked", () => {
1689
+ const r = runHook("migration-guard.js", {
1690
+ tool_input: { file_path: "supabase/migrations/006.sql", content: "CREATE TEMP TABLE scratch (id int);" },
1691
+ });
1692
+ assert.equal(r.status, 0, "TEMP tables should be exempt from the RLS requirement");
1693
+ });
1694
+
1695
+ it("migration-guard: MigrationModal.tsx is NOT scanned", () => {
1696
+ const r = runHook("migration-guard.js", {
1697
+ tool_input: { file_path: "src/components/MigrationModal.tsx", content: "DROP TABLE users;" },
1698
+ });
1699
+ assert.equal(r.status, 0, "files with 'migration' in the name but not in a migrations/ dir should not be scanned");
1700
+ });
1306
1701
  });
1307
1702
 
1308
1703
  // ═══════════════════════════════════════════════════════════
@@ -895,6 +895,46 @@ else
895
895
  fail_case "first-time init lifetime" "got=$RESULT expected=1,0,0,0,0"
896
896
  fi
897
897
 
898
+ # ─── Backfill lifetime ───────────────────────────────────
899
+ echo ""
900
+ echo "backfill-lifetime:"
901
+
902
+ # 50. backfill-lifetime reconstructs from completed phases
903
+ TMP=$(make_project)
904
+ make_valid_plan "$TMP" 1
905
+ touch "$TMP/.planning/phase-1-verification.md"
906
+ (cd "$TMP" && $NODE "$STATE_JS" transition --to planned >/dev/null 2>&1)
907
+ (cd "$TMP" && $NODE "$STATE_JS" transition --to built --tasks-done 3 --tasks-total 3 >/dev/null 2>&1)
908
+ (cd "$TMP" && $NODE "$STATE_JS" transition --to verified --verification pass >/dev/null 2>&1)
909
+ # Wipe lifetime to simulate pre-v3.4.0 state
910
+ $NODE -e "
911
+ const t = JSON.parse(require('fs').readFileSync('$TMP/.planning/tracking.json','utf8'));
912
+ t.lifetime = { tasks_completed: 0, phases_completed: 0, milestones_completed: 0, total_phases: 0 };
913
+ require('fs').writeFileSync('$TMP/.planning/tracking.json', JSON.stringify(t, null, 2));
914
+ "
915
+ OUT=$(cd "$TMP" && $NODE "$STATE_JS" backfill-lifetime 2>&1)
916
+ EXIT=$?
917
+ if [ "$EXIT" -eq 0 ] \
918
+ && echo "$OUT" | grep -q '"action": "backfill-lifetime"' \
919
+ && echo "$OUT" | grep -q '"phases_completed": 1' \
920
+ && echo "$OUT" | grep -q '"tasks_completed": 1'; then
921
+ pass "backfill-lifetime reconstructs 1 phase, 1 task from plan file"
922
+ else
923
+ fail_case "backfill-lifetime" "exit=$EXIT out=$OUT"
924
+ fi
925
+
926
+ # 51. backfill-lifetime is idempotent
927
+ OUT2=$(cd "$TMP" && $NODE "$STATE_JS" backfill-lifetime 2>&1)
928
+ RESULT=$($NODE -e "
929
+ const t = JSON.parse(require('fs').readFileSync('$TMP/.planning/tracking.json','utf8'));
930
+ console.log([t.lifetime.tasks_completed, t.lifetime.phases_completed].join(','));
931
+ ")
932
+ if [ "$RESULT" = "1,1" ]; then
933
+ pass "backfill-lifetime is idempotent (same result on re-run)"
934
+ else
935
+ fail_case "backfill idempotent" "got=$RESULT"
936
+ fi
937
+
898
938
  # ─── Summary ─────────────────────────────────────────────
899
939
  echo ""
900
940
  echo "=== Results: $PASS passed, $FAIL failed ==="
@@ -1,8 +0,0 @@
1
- ---
2
- name: qualia-idk
3
- description: "Alias for /qualia. The smart router handles all 'idk', 'what now', 'I'm stuck' situations."
4
- ---
5
-
6
- # /qualia-idk
7
-
8
- This is an alias for `/qualia`. Run `/qualia` — it now handles all situation classification and routing.