@nathapp/nax 0.22.4 → 0.24.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/bin/nax.ts +20 -2
- package/docs/tdd/strategies.md +97 -0
- package/nax/features/central-run-registry/prd.json +105 -0
- package/nax/features/diagnose/acceptance.test.ts +3 -1
- package/package.json +3 -3
- package/src/cli/diagnose.ts +1 -1
- package/src/cli/status-features.ts +55 -7
- package/src/commands/index.ts +1 -0
- package/src/commands/logs.ts +87 -17
- package/src/commands/runs.ts +220 -0
- package/src/config/schemas.ts +3 -0
- package/src/execution/crash-recovery.ts +30 -7
- package/src/execution/lifecycle/run-setup.ts +6 -1
- package/src/execution/runner.ts +8 -0
- package/src/execution/sequential-executor.ts +4 -0
- package/src/execution/status-writer.ts +42 -0
- package/src/pipeline/subscribers/events-writer.ts +121 -0
- package/src/pipeline/subscribers/registry.ts +73 -0
- package/src/version.ts +23 -0
- package/test/e2e/plan-analyze-run.test.ts +5 -0
- package/test/integration/cli/cli-diagnose.test.ts +3 -1
- package/test/integration/cli/cli-logs.test.ts +40 -17
- package/test/integration/execution/feature-status-write.test.ts +302 -0
- package/test/integration/execution/status-file-integration.test.ts +1 -1
- package/test/integration/execution/status-writer.test.ts +112 -0
- package/test/unit/cli-status-project-level.test.ts +283 -0
- package/test/unit/commands/logs.test.ts +63 -22
- package/test/unit/commands/runs.test.ts +303 -0
- package/test/unit/config/quality-commands-schema.test.ts +72 -0
- package/test/unit/execution/sfc-004-dead-code-cleanup.test.ts +89 -0
- package/test/unit/pipeline/subscribers/events-writer.test.ts +227 -0
- package/test/unit/pipeline/subscribers/registry.test.ts +149 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
5
|
+
import { PipelineEventBus } from "../../../../src/pipeline/event-bus";
|
|
6
|
+
import { type MetaJson, wireRegistry } from "../../../../src/pipeline/subscribers/registry";
|
|
7
|
+
|
|
8
|
+
describe("wireRegistry", () => {
|
|
9
|
+
let workdir: string;
|
|
10
|
+
let feature: string;
|
|
11
|
+
let runId: string;
|
|
12
|
+
let runDir: string;
|
|
13
|
+
let metaFile: string;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
workdir = join("/tmp", `nax-regtest-${Date.now()}`);
|
|
17
|
+
feature = "auth-system";
|
|
18
|
+
runId = `run-${Date.now()}`;
|
|
19
|
+
const project = basename(workdir);
|
|
20
|
+
runDir = join(homedir(), ".nax", "runs", `${project}-${feature}-${runId}`);
|
|
21
|
+
metaFile = join(runDir, "meta.json");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await rm(runDir, { recursive: true, force: true });
|
|
26
|
+
mock.restore();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("returns an UnsubscribeFn", () => {
|
|
30
|
+
const bus = new PipelineEventBus();
|
|
31
|
+
const unsub = wireRegistry(bus, feature, runId, workdir);
|
|
32
|
+
expect(typeof unsub).toBe("function");
|
|
33
|
+
unsub();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("creates meta.json on run:started", async () => {
|
|
37
|
+
const bus = new PipelineEventBus();
|
|
38
|
+
wireRegistry(bus, feature, runId, workdir);
|
|
39
|
+
|
|
40
|
+
bus.emit({ type: "run:started", feature, totalStories: 3, workdir });
|
|
41
|
+
|
|
42
|
+
await Bun.sleep(50);
|
|
43
|
+
const text = await readFile(metaFile, "utf8");
|
|
44
|
+
const meta = JSON.parse(text) as MetaJson;
|
|
45
|
+
expect(meta).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("meta.json contains all required fields", async () => {
|
|
49
|
+
const bus = new PipelineEventBus();
|
|
50
|
+
wireRegistry(bus, feature, runId, workdir);
|
|
51
|
+
|
|
52
|
+
bus.emit({ type: "run:started", feature, totalStories: 1, workdir });
|
|
53
|
+
|
|
54
|
+
await Bun.sleep(50);
|
|
55
|
+
const meta = JSON.parse(await readFile(metaFile, "utf8")) as MetaJson;
|
|
56
|
+
|
|
57
|
+
expect(meta.runId).toBe(runId);
|
|
58
|
+
expect(meta.project).toBe(basename(workdir));
|
|
59
|
+
expect(meta.feature).toBe(feature);
|
|
60
|
+
expect(meta.workdir).toBe(workdir);
|
|
61
|
+
expect(typeof meta.statusPath).toBe("string");
|
|
62
|
+
expect(typeof meta.eventsDir).toBe("string");
|
|
63
|
+
expect(typeof meta.registeredAt).toBe("string");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("statusPath points to <workdir>/nax/features/<feature>/status.json", async () => {
|
|
67
|
+
const bus = new PipelineEventBus();
|
|
68
|
+
wireRegistry(bus, feature, runId, workdir);
|
|
69
|
+
|
|
70
|
+
bus.emit({ type: "run:started", feature, totalStories: 1, workdir });
|
|
71
|
+
|
|
72
|
+
await Bun.sleep(50);
|
|
73
|
+
const meta = JSON.parse(await readFile(metaFile, "utf8")) as MetaJson;
|
|
74
|
+
|
|
75
|
+
expect(meta.statusPath).toBe(join(workdir, "nax", "features", feature, "status.json"));
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("eventsDir points to <workdir>/nax/features/<feature>/runs", async () => {
|
|
79
|
+
const bus = new PipelineEventBus();
|
|
80
|
+
wireRegistry(bus, feature, runId, workdir);
|
|
81
|
+
|
|
82
|
+
bus.emit({ type: "run:started", feature, totalStories: 1, workdir });
|
|
83
|
+
|
|
84
|
+
await Bun.sleep(50);
|
|
85
|
+
const meta = JSON.parse(await readFile(metaFile, "utf8")) as MetaJson;
|
|
86
|
+
|
|
87
|
+
expect(meta.eventsDir).toBe(join(workdir, "nax", "features", feature, "runs"));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("registeredAt is valid ISO8601", async () => {
|
|
91
|
+
const bus = new PipelineEventBus();
|
|
92
|
+
wireRegistry(bus, feature, runId, workdir);
|
|
93
|
+
|
|
94
|
+
bus.emit({ type: "run:started", feature, totalStories: 1, workdir });
|
|
95
|
+
|
|
96
|
+
await Bun.sleep(50);
|
|
97
|
+
const meta = JSON.parse(await readFile(metaFile, "utf8")) as MetaJson;
|
|
98
|
+
|
|
99
|
+
expect(() => new Date(meta.registeredAt).toISOString()).not.toThrow();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("write failure does not throw or crash", async () => {
|
|
103
|
+
const bus = new PipelineEventBus();
|
|
104
|
+
// Point to an unwritable path to trigger write failure
|
|
105
|
+
const badWorkdir = "/dev/null/nonexistent-project";
|
|
106
|
+
wireRegistry(bus, "feat-err", "run-err", badWorkdir);
|
|
107
|
+
|
|
108
|
+
expect(() => {
|
|
109
|
+
bus.emit({ type: "run:started", feature: "feat-err", totalStories: 0, workdir: badWorkdir });
|
|
110
|
+
}).not.toThrow();
|
|
111
|
+
|
|
112
|
+
await Bun.sleep(50);
|
|
113
|
+
// No crash — test passes if we reach here
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("MetaJson interface is exported", () => {
|
|
117
|
+
// Verify that MetaJson can be used as a type annotation
|
|
118
|
+
const meta: MetaJson = {
|
|
119
|
+
runId: "r1",
|
|
120
|
+
project: "proj",
|
|
121
|
+
feature: "feat",
|
|
122
|
+
workdir: "/tmp/proj",
|
|
123
|
+
statusPath: "/tmp/proj/nax/features/feat/status.json",
|
|
124
|
+
eventsDir: "/tmp/proj/nax/features/feat/runs",
|
|
125
|
+
registeredAt: new Date().toISOString(),
|
|
126
|
+
};
|
|
127
|
+
expect(meta.runId).toBe("r1");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("unsubscribe stops further writes", async () => {
|
|
131
|
+
const bus = new PipelineEventBus();
|
|
132
|
+
const unsub = wireRegistry(bus, feature, runId, workdir);
|
|
133
|
+
|
|
134
|
+
unsub();
|
|
135
|
+
|
|
136
|
+
bus.emit({ type: "run:started", feature, totalStories: 1, workdir });
|
|
137
|
+
|
|
138
|
+
await Bun.sleep(50);
|
|
139
|
+
// File should not exist since we unsubscribed before event
|
|
140
|
+
let exists = false;
|
|
141
|
+
try {
|
|
142
|
+
await readFile(metaFile, "utf8");
|
|
143
|
+
exists = true;
|
|
144
|
+
} catch {
|
|
145
|
+
exists = false;
|
|
146
|
+
}
|
|
147
|
+
expect(exists).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
});
|