@warpgogol/forge 9.2.3 → 9.3.1
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/CHANGELOG.md +33 -0
- package/bin/cli.ts +3 -2
- package/dist/bin/cli.js +3 -2
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/adr/handlers/implement-stamp.d.ts +6 -0
- package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/adr/handlers/implement-stamp.js +23 -15
- package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
- package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -1
- package/dist/os/checks/handlers/counters-journal.js +9 -1
- package/dist/os/checks/handlers/counters-journal.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +27 -36
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/lock-holder.d.ts +32 -0
- package/dist/os/core/lock-holder.d.ts.map +1 -0
- package/dist/os/core/lock-holder.js +81 -0
- package/dist/os/core/lock-holder.js.map +1 -0
- package/dist/os/core/stamp-lock.d.ts +30 -0
- package/dist/os/core/stamp-lock.d.ts.map +1 -0
- package/dist/os/core/stamp-lock.js +112 -0
- package/dist/os/core/stamp-lock.js.map +1 -0
- package/dist/os/flow/digest.d.ts +19 -0
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +33 -4
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +61 -6
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-cut.d.ts +8 -0
- package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-cut.js +91 -5
- package/dist/os/flow/handlers/flow-cut.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +6 -0
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-discard.js +17 -13
- package/dist/os/flow/handlers/flow-discard.js.map +1 -1
- package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-fix.js +99 -10
- package/dist/os/flow/handlers/flow-fix.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +32 -15
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/handlers/flow-publication-retire.d.ts +17 -0
- package/dist/os/flow/handlers/flow-publication-retire.d.ts.map +1 -0
- package/dist/os/flow/handlers/flow-publication-retire.js +132 -0
- package/dist/os/flow/handlers/flow-publication-retire.js.map +1 -0
- package/dist/os/flow/handlers/flow-push.d.ts +7 -0
- package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-push.js +106 -15
- package/dist/os/flow/handlers/flow-push.js.map +1 -1
- package/dist/os/flow/locks.d.ts +6 -1
- package/dist/os/flow/locks.d.ts.map +1 -1
- package/dist/os/flow/locks.js +53 -23
- package/dist/os/flow/locks.js.map +1 -1
- package/dist/os/flow/publication-order.d.ts +25 -0
- package/dist/os/flow/publication-order.d.ts.map +1 -0
- package/dist/os/flow/publication-order.js +75 -0
- package/dist/os/flow/publication-order.js.map +1 -0
- package/dist/os/flow/publish.d.ts +18 -0
- package/dist/os/flow/publish.d.ts.map +1 -1
- package/dist/os/flow/publish.js +58 -2
- package/dist/os/flow/publish.js.map +1 -1
- package/dist/os/flow/registry.d.ts +1 -1
- package/dist/os/flow/registry.d.ts.map +1 -1
- package/dist/os/flow/registry.js +2 -1
- package/dist/os/flow/registry.js.map +1 -1
- package/dist/os/flow/release-tags.d.ts +1 -0
- package/dist/os/flow/release-tags.d.ts.map +1 -1
- package/dist/os/flow/release-tags.js +5 -4
- package/dist/os/flow/release-tags.js.map +1 -1
- package/dist/os/flow/scripts.d.ts +1 -1
- package/dist/os/flow/scripts.d.ts.map +1 -1
- package/dist/os/flow/scripts.js +6 -1
- package/dist/os/flow/scripts.js.map +1 -1
- package/dist/os/flow/task-files.d.ts +11 -0
- package/dist/os/flow/task-files.d.ts.map +1 -0
- package/dist/os/flow/task-files.js +51 -0
- package/dist/os/flow/task-files.js.map +1 -0
- package/dist/os/flow/tests/helpers.d.ts +4 -1
- package/dist/os/flow/tests/helpers.d.ts.map +1 -1
- package/dist/os/flow/tests/helpers.js +9 -5
- package/dist/os/flow/tests/helpers.js.map +1 -1
- package/dist/os/mission/handlers/archive.d.ts.map +1 -1
- package/dist/os/mission/handlers/archive.js +30 -74
- package/dist/os/mission/handlers/archive.js.map +1 -1
- package/dist/os/mission/lockfile.d.ts +21 -0
- package/dist/os/mission/lockfile.d.ts.map +1 -0
- package/dist/os/mission/lockfile.js +76 -0
- package/dist/os/mission/lockfile.js.map +1 -0
- package/dist/os/mission/mission.module.d.ts.map +1 -1
- package/dist/os/mission/mission.module.js +2 -1
- package/dist/os/mission/mission.module.js.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.d.ts +6 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +24 -19
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/system/handlers/outbox-validate.d.ts +8 -0
- package/dist/os/system/handlers/outbox-validate.d.ts.map +1 -0
- package/dist/os/system/handlers/outbox-validate.js +102 -0
- package/dist/os/system/handlers/outbox-validate.js.map +1 -0
- package/dist/os/system/handlers/system-map-validate.d.ts +13 -0
- package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -0
- package/dist/os/system/handlers/system-map-validate.js +78 -0
- package/dist/os/system/handlers/system-map-validate.js.map +1 -0
- package/dist/os/system/handlers/system-outbox-scan.d.ts +10 -0
- package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -0
- package/dist/os/system/handlers/system-outbox-scan.js +195 -0
- package/dist/os/system/handlers/system-outbox-scan.js.map +1 -0
- package/dist/os/system/handlers/system-task-collect.d.ts +13 -0
- package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-collect.js +238 -0
- package/dist/os/system/handlers/system-task-collect.js.map +1 -0
- package/dist/os/system/handlers/system-task-create.d.ts +32 -0
- package/dist/os/system/handlers/system-task-create.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-create.js +216 -0
- package/dist/os/system/handlers/system-task-create.js.map +1 -0
- package/dist/os/system/handlers/system-task-dispatch.d.ts +14 -0
- package/dist/os/system/handlers/system-task-dispatch.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-dispatch.js +290 -0
- package/dist/os/system/handlers/system-task-dispatch.js.map +1 -0
- package/dist/os/system/handlers/system-task-move.d.ts +12 -0
- package/dist/os/system/handlers/system-task-move.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-move.js +217 -0
- package/dist/os/system/handlers/system-task-move.js.map +1 -0
- package/dist/os/system/handlers/system-task-status.d.ts +20 -0
- package/dist/os/system/handlers/system-task-status.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-status.js +139 -0
- package/dist/os/system/handlers/system-task-status.js.map +1 -0
- package/dist/os/system/handlers/system-versionset-record.d.ts +12 -0
- package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -0
- package/dist/os/system/handlers/system-versionset-record.js +332 -0
- package/dist/os/system/handlers/system-versionset-record.js.map +1 -0
- package/dist/os/system/index.d.ts +6 -0
- package/dist/os/system/index.d.ts.map +1 -0
- package/dist/os/system/index.js +18 -0
- package/dist/os/system/index.js.map +1 -0
- package/dist/os/system/outbox-schema.d.ts +30 -0
- package/dist/os/system/outbox-schema.d.ts.map +1 -0
- package/dist/os/system/outbox-schema.js +29 -0
- package/dist/os/system/outbox-schema.js.map +1 -0
- package/dist/os/system/repo.d.ts +64 -0
- package/dist/os/system/repo.d.ts.map +1 -0
- package/dist/os/system/repo.js +364 -0
- package/dist/os/system/repo.js.map +1 -0
- package/dist/os/system/scenario-schemas.d.ts +26 -0
- package/dist/os/system/scenario-schemas.d.ts.map +1 -0
- package/dist/os/system/scenario-schemas.js +53 -0
- package/dist/os/system/scenario-schemas.js.map +1 -0
- package/dist/os/system/schemas.d.ts +63 -0
- package/dist/os/system/schemas.d.ts.map +1 -0
- package/dist/os/system/schemas.js +83 -0
- package/dist/os/system/schemas.js.map +1 -0
- package/dist/os/system/system.module.d.ts +3 -0
- package/dist/os/system/system.module.d.ts.map +1 -0
- package/dist/os/system/system.module.js +429 -0
- package/dist/os/system/system.module.js.map +1 -0
- package/dist/os/system/task-schemas.d.ts +108 -0
- package/dist/os/system/task-schemas.d.ts.map +1 -0
- package/dist/os/system/task-schemas.js +152 -0
- package/dist/os/system/task-schemas.js.map +1 -0
- package/dist/os/system/task-store.d.ts +41 -0
- package/dist/os/system/task-store.d.ts.map +1 -0
- package/dist/os/system/task-store.js +142 -0
- package/dist/os/system/task-store.js.map +1 -0
- package/dist/os/system/tests/helpers.d.ts +30 -0
- package/dist/os/system/tests/helpers.d.ts.map +1 -0
- package/dist/os/system/tests/helpers.js +178 -0
- package/dist/os/system/tests/helpers.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -4
- package/dist/src/index.js.map +1 -1
- package/os/adr/handlers/implement-stamp-lock.test.ts +90 -0
- package/os/adr/handlers/implement-stamp.ts +29 -20
- package/os/checks/handlers/counters-journal.test.ts +10 -0
- package/os/checks/handlers/counters-journal.ts +8 -1
- package/os/core/core.module.ts +32 -36
- package/os/core/lock-holder.ts +88 -0
- package/os/core/stamp-lock.ts +142 -0
- package/os/flow/digest.ts +46 -4
- package/os/flow/flow.module.ts +62 -6
- package/os/flow/handlers/flow-cut.ts +118 -5
- package/os/flow/handlers/flow-digest.ts +6 -0
- package/os/flow/handlers/flow-discard.ts +22 -13
- package/os/flow/handlers/flow-fix.ts +116 -10
- package/os/flow/handlers/flow-integrate.ts +31 -15
- package/os/flow/handlers/flow-publication-retire.ts +156 -0
- package/os/flow/handlers/flow-push.ts +128 -13
- package/os/flow/locks.ts +75 -25
- package/os/flow/publication-order.ts +99 -0
- package/os/flow/publish.ts +73 -2
- package/os/flow/registry.ts +5 -2
- package/os/flow/release-tags.ts +5 -4
- package/os/flow/scripts.ts +12 -5
- package/os/flow/task-files.ts +59 -0
- package/os/flow/tests/flow-cut-prepare.test.ts +298 -0
- package/os/flow/tests/flow-cut.test.ts +5 -1
- package/os/flow/tests/flow-publication-retire.test.ts +191 -0
- package/os/flow/tests/flow-push-supersede.test.ts +221 -0
- package/os/flow/tests/flow-task-files.test.ts +59 -0
- package/os/flow/tests/helpers.ts +9 -5
- package/os/flow/tests/locks.test.ts +219 -0
- package/os/flow/tests/publication-order.test.ts +102 -0
- package/os/flow/tests/scripts.test.ts +13 -0
- package/os/mission/handlers/archive.test.ts +97 -52
- package/os/mission/handlers/archive.ts +31 -76
- package/os/mission/lockfile.ts +84 -0
- package/os/mission/mission.module.ts +2 -1
- package/os/rfc/handlers/implement-stamp-lock.test.ts +133 -0
- package/os/rfc/handlers/implement-stamp.ts +30 -24
- package/os/system/handlers/outbox-validate.ts +120 -0
- package/os/system/handlers/system-map-validate.ts +107 -0
- package/os/system/handlers/system-outbox-scan.ts +320 -0
- package/os/system/handlers/system-task-collect.ts +305 -0
- package/os/system/handlers/system-task-create.ts +271 -0
- package/os/system/handlers/system-task-dispatch.ts +387 -0
- package/os/system/handlers/system-task-move.ts +353 -0
- package/os/system/handlers/system-task-status.ts +176 -0
- package/os/system/handlers/system-versionset-record.ts +476 -0
- package/os/system/index.ts +47 -0
- package/os/system/outbox-schema.ts +47 -0
- package/os/system/repo.ts +451 -0
- package/os/system/scenario-schemas.ts +62 -0
- package/os/system/schemas.ts +102 -0
- package/os/system/system.module.ts +449 -0
- package/os/system/task-schemas.ts +190 -0
- package/os/system/task-store.ts +184 -0
- package/os/system/tests/helpers.ts +189 -0
- package/os/system/tests/outbox-validate.test.ts +92 -0
- package/os/system/tests/system-map-validate.test.ts +321 -0
- package/os/system/tests/system-outbox-scan.test.ts +273 -0
- package/os/system/tests/system-profile.test.ts +90 -0
- package/os/system/tests/system-task-collect.test.ts +293 -0
- package/os/system/tests/system-task-dispatch.test.ts +279 -0
- package/os/system/tests/system-task-status.test.ts +153 -0
- package/os/system/tests/system-task.test.ts +330 -0
- package/os/system/tests/system-versionset.test.ts +314 -0
- package/package.json +33 -1
- package/profiles/forge-shell.yaml +1 -2
- package/profiles/knowledge.yaml +1 -1
- package/profiles/system.yaml +650 -0
- package/profiles/typescript.yaml +0 -1
- package/skills/fo/fo-outbox/SKILL.md +71 -0
- package/skills/fo/fo-system-dispatch/SKILL.md +65 -0
- package/skills/fo/fo-task-run/SKILL.md +75 -0
- package/src/index.ts +11 -4
- package/src/tests/fixtures/agents-generate-business-before.txt +6 -0
- package/src/tests/profile-flow-hooks.test.ts +15 -0
- package/src/tests/profile-schema.test.ts +2 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>File store for the system task queue (RFC-1509): read/write/list of
|
|
4
|
+
queue/tasks/T-NNNN.yaml files (forge/system-task@1), the next-id allocator,
|
|
5
|
+
the dispatch-brief reader/writer and the report copy. All mutation paths go
|
|
6
|
+
through the injected WorkspaceIO so kernel callers stay on the recording
|
|
7
|
+
adapter.</purpose>
|
|
8
|
+
<non-goals>
|
|
9
|
+
<item>No transition checks — handlers own the table lookups.</item>
|
|
10
|
+
</non-goals>
|
|
11
|
+
</MODULE_CONTRACT>
|
|
12
|
+
<CHANGE_SUMMARY>
|
|
13
|
+
<item>RFC-1509: step 2 — task store (read/write/list/next-id, brief IO)</item>
|
|
14
|
+
<item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
|
|
15
|
+
<item>RFC-1509: close RFC-1509 review r1 findings — mark-failed escape, open-error refusal, dry-run coverage</item>
|
|
16
|
+
</CHANGE_SUMMARY>
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import YAML from "yaml";
|
|
21
|
+
|
|
22
|
+
import type { Diagnostic, WorkspaceIO } from "../../src/types.ts";
|
|
23
|
+
import { systemTaskSchema, TASK_ID_RE, type SystemTask } from "./task-schemas.ts";
|
|
24
|
+
|
|
25
|
+
export const TASKS_DIR = "queue/tasks";
|
|
26
|
+
export const BRIEFS_DIR = "queue/briefs";
|
|
27
|
+
export const REPORTS_DIR = "queue/reports";
|
|
28
|
+
|
|
29
|
+
export function taskFilePath(root: string, id: string): string {
|
|
30
|
+
return path.join(root, TASKS_DIR, `${id}.yaml`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function briefFilePath(root: string, id: string): string {
|
|
34
|
+
return path.join(root, BRIEFS_DIR, `${id}.md`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function reportFilePath(root: string, id: string): string {
|
|
38
|
+
return path.join(root, REPORTS_DIR, `${id}.yaml`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function taskDiag(ruleId: string, message: string, file?: string): Diagnostic {
|
|
42
|
+
return { ruleId, severity: "error", message, file };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function schemaIssues(error: { issues: { path: PropertyKey[]; message: string }[] }): string {
|
|
46
|
+
return error.issues
|
|
47
|
+
.map((issue) => `${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`)
|
|
48
|
+
.join("; ");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Read one task file. SYSTEM-TASK-01 when the file is missing or fails the
|
|
53
|
+
* forge/system-task@1 schema — never throws on malformed input.
|
|
54
|
+
*/
|
|
55
|
+
export async function readTask(
|
|
56
|
+
root: string,
|
|
57
|
+
io: WorkspaceIO,
|
|
58
|
+
id: string,
|
|
59
|
+
): Promise<{ task: SystemTask | null; diagnostic: Diagnostic | null }> {
|
|
60
|
+
const file = taskFilePath(root, id);
|
|
61
|
+
if (!(await io.exists(file))) {
|
|
62
|
+
return {
|
|
63
|
+
task: null,
|
|
64
|
+
diagnostic: taskDiag(
|
|
65
|
+
"SYSTEM-TASK-01",
|
|
66
|
+
`unknown task ${id} — no file at ${path.relative(root, file)}`,
|
|
67
|
+
path.relative(root, file),
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
let raw: unknown;
|
|
72
|
+
try {
|
|
73
|
+
raw = YAML.parse(await io.readFile(file));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
task: null,
|
|
77
|
+
diagnostic: taskDiag(
|
|
78
|
+
"SYSTEM-TASK-01",
|
|
79
|
+
`${path.relative(root, file)} is not parseable YAML: ${error instanceof Error ? error.message : String(error)}`,
|
|
80
|
+
path.relative(root, file),
|
|
81
|
+
),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const parsed = systemTaskSchema.safeParse(raw);
|
|
85
|
+
if (!parsed.success) {
|
|
86
|
+
return {
|
|
87
|
+
task: null,
|
|
88
|
+
diagnostic: taskDiag(
|
|
89
|
+
"SYSTEM-TASK-01",
|
|
90
|
+
`${path.relative(root, file)} fails forge/system-task@1: ${schemaIssues(parsed.error)}`,
|
|
91
|
+
path.relative(root, file),
|
|
92
|
+
),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return { task: parsed.data, diagnostic: null };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Write a task file (creates queue/tasks/ when absent). */
|
|
99
|
+
export async function writeTask(
|
|
100
|
+
root: string,
|
|
101
|
+
io: WorkspaceIO,
|
|
102
|
+
task: SystemTask,
|
|
103
|
+
): Promise<void> {
|
|
104
|
+
const file = taskFilePath(root, task.id);
|
|
105
|
+
await io.mkdir(path.dirname(file));
|
|
106
|
+
await io.writeFile(file, YAML.stringify(task));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* List every task file under queue/tasks/. Files that fail the schema are
|
|
111
|
+
* reported as SYSTEM-TASK-01 diagnostics and skipped — the listing itself
|
|
112
|
+
* never throws.
|
|
113
|
+
*/
|
|
114
|
+
export async function listTasks(
|
|
115
|
+
root: string,
|
|
116
|
+
io: WorkspaceIO,
|
|
117
|
+
): Promise<{ tasks: SystemTask[]; diagnostics: Diagnostic[] }> {
|
|
118
|
+
const dir = path.join(root, TASKS_DIR);
|
|
119
|
+
const tasks: SystemTask[] = [];
|
|
120
|
+
const diagnostics: Diagnostic[] = [];
|
|
121
|
+
if (!(await io.exists(dir))) return { tasks, diagnostics };
|
|
122
|
+
const entries = await io.readdir(dir);
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
if (!entry.isFile || !entry.name.endsWith(".yaml")) continue;
|
|
125
|
+
const id = entry.name.slice(0, -".yaml".length);
|
|
126
|
+
if (!TASK_ID_RE.test(id)) continue;
|
|
127
|
+
const { task, diagnostic } = await readTask(root, io, id);
|
|
128
|
+
if (diagnostic) diagnostics.push(diagnostic);
|
|
129
|
+
if (task) tasks.push(task);
|
|
130
|
+
}
|
|
131
|
+
tasks.sort((a, b) => a.id.localeCompare(b.id));
|
|
132
|
+
return { tasks, diagnostics };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Highest T-NNNN in queue/tasks/ plus one, zero-padded to four digits. */
|
|
136
|
+
export async function nextTaskId(root: string, io: WorkspaceIO): Promise<string> {
|
|
137
|
+
const dir = path.join(root, TASKS_DIR);
|
|
138
|
+
let max = 0;
|
|
139
|
+
if (await io.exists(dir)) {
|
|
140
|
+
for (const entry of await io.readdir(dir)) {
|
|
141
|
+
const m = /^T-(\d{4})\.yaml$/.exec(entry.name);
|
|
142
|
+
if (m) max = Math.max(max, Number(m[1]));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return `T-${String(max + 1).padStart(4, "0")}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Dispatch brief
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
export interface LoadedBrief {
|
|
153
|
+
/** Full markdown content — written verbatim into the product worktree. */
|
|
154
|
+
content: string;
|
|
155
|
+
/** Parsed frontmatter, or null when the file fails to parse/validate. */
|
|
156
|
+
frontmatter: Record<string, unknown> | null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Read queue/briefs/<id>.md and split out the YAML frontmatter block. Returns
|
|
161
|
+
* null when the file is absent.
|
|
162
|
+
*/
|
|
163
|
+
export async function readBrief(
|
|
164
|
+
root: string,
|
|
165
|
+
io: WorkspaceIO,
|
|
166
|
+
id: string,
|
|
167
|
+
): Promise<LoadedBrief | null> {
|
|
168
|
+
const file = briefFilePath(root, id);
|
|
169
|
+
if (!(await io.exists(file))) return null;
|
|
170
|
+
const content = await io.readFile(file);
|
|
171
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
|
|
172
|
+
let frontmatter: Record<string, unknown> | null = null;
|
|
173
|
+
if (match) {
|
|
174
|
+
try {
|
|
175
|
+
const parsed = YAML.parse(match[1]);
|
|
176
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
177
|
+
frontmatter = parsed as Record<string, unknown>;
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
frontmatter = null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { content, frontmatter };
|
|
184
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Test helpers for forge system-module suites (RFC-1508) — makeSystemRepo
|
|
4
|
+
materializes a temporary system-profile repository under os.tmpdir();
|
|
5
|
+
makeContext builds a ForgeRuntimeContext for direct handler invocation;
|
|
6
|
+
canonical YAML fixture strings keep tests focused on the variable under test.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>Fixtures only — no test assertions here.</item>
|
|
9
|
+
</non-goals>
|
|
10
|
+
</MODULE_CONTRACT>
|
|
11
|
+
<CHANGE_SUMMARY>
|
|
12
|
+
<item>RFC-1508: step 1 — shared system test helpers (RFC-1509..1511 reuse)</item>
|
|
13
|
+
<item>RFC-1508: implement RFC-1508 — system profile, system map schemas and system.map.validate</item>
|
|
14
|
+
<item>RFC-1508: align rfc-1508 schemas with the normative contract after review r1</item>
|
|
15
|
+
<item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
|
|
16
|
+
</CHANGE_SUMMARY>
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// @vitest-environment node
|
|
20
|
+
|
|
21
|
+
import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
|
|
22
|
+
import os from "node:os";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
|
|
25
|
+
import type { ForgeRuntimeContext } from "../../../src/types.ts";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Write a temporary repository: `forge.yaml` declares `profile: system`
|
|
29
|
+
* (overridable via files["forge.yaml"]) plus every entry in `files` at its
|
|
30
|
+
* repo-relative path. Returns the repo root.
|
|
31
|
+
*/
|
|
32
|
+
export async function makeSystemRepo(files: Record<string, string> = {}): Promise<string> {
|
|
33
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "forge-system-"));
|
|
34
|
+
const all = { "forge.yaml": "profile: system\n", ...files };
|
|
35
|
+
for (const [rel, content] of Object.entries(all)) {
|
|
36
|
+
const abs = path.join(root, rel);
|
|
37
|
+
await mkdir(path.dirname(abs), { recursive: true });
|
|
38
|
+
await writeFile(abs, content);
|
|
39
|
+
}
|
|
40
|
+
return root;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function makeContext(root: string): ForgeRuntimeContext {
|
|
44
|
+
const sink = (_msg: string, _details?: unknown): void => {};
|
|
45
|
+
return {
|
|
46
|
+
workspaceRoot: root,
|
|
47
|
+
logger: { section: sink, info: sink, warn: sink, error: sink, success: sink },
|
|
48
|
+
dryRun: false,
|
|
49
|
+
outputFormat: "json",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Canonical fixtures
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
export const VALID_SYSTEM_YAML = `schema: forge/system@1
|
|
58
|
+
id: demo-system
|
|
59
|
+
name: Demo System
|
|
60
|
+
owners:
|
|
61
|
+
- ops
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
export const VALID_PRODUCTS_YAML = `schema: forge/system-products@1
|
|
65
|
+
products:
|
|
66
|
+
- id: alpha
|
|
67
|
+
remote: https://example.invalid/alpha.git
|
|
68
|
+
offers:
|
|
69
|
+
- alpha-contract
|
|
70
|
+
- id: beta
|
|
71
|
+
remote: https://example.invalid/beta.git
|
|
72
|
+
offers: []
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
export const VALID_EDGES_YAML = `schema: forge/system-edges@1
|
|
76
|
+
allowed:
|
|
77
|
+
- consumer: beta
|
|
78
|
+
contract: alpha-contract
|
|
79
|
+
forbidden: []
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A fully valid repository: all three map files plus a products.local.yaml
|
|
84
|
+
* mapping both products to existing folders (created via .gitkeep entries).
|
|
85
|
+
*/
|
|
86
|
+
export function validMapFiles(): Record<string, string> {
|
|
87
|
+
return {
|
|
88
|
+
"system/system.yaml": VALID_SYSTEM_YAML,
|
|
89
|
+
"system/products.yaml": VALID_PRODUCTS_YAML,
|
|
90
|
+
"system/edges.yaml": VALID_EDGES_YAML,
|
|
91
|
+
"system/products.local.yaml": `schema: forge/system-products-local@1
|
|
92
|
+
folders:
|
|
93
|
+
alpha: ./alpha
|
|
94
|
+
beta: ./beta
|
|
95
|
+
launcher:
|
|
96
|
+
argv: [echo, "{worktree}", "{task}"]
|
|
97
|
+
`,
|
|
98
|
+
"alpha/.gitkeep": "",
|
|
99
|
+
"beta/.gitkeep": "",
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// RFC-1509 product fixtures — governed product repos under os.tmpdir()
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Materialize a governed product repository: `git init` on main, a forge.yaml
|
|
109
|
+
* seed commit and a `develop` branch — the minimum openFlowBranchCore asks
|
|
110
|
+
* for. Lives OUTSIDE the system repo so dispatch resolves a real checkout.
|
|
111
|
+
* Returns the absolute product root.
|
|
112
|
+
*/
|
|
113
|
+
export async function makeProduct(prefix = "forge-product-"): Promise<string> {
|
|
114
|
+
const { gitExec } = await import("../../flow/tests/helpers.ts");
|
|
115
|
+
const root = await mkdtemp(path.join(os.tmpdir(), prefix));
|
|
116
|
+
const init = await gitExec(root, ["init", "-b", "main"]);
|
|
117
|
+
if (init.exitCode !== 0) throw new Error(`git init failed: ${init.stderr}`);
|
|
118
|
+
await gitExec(root, ["config", "user.email", "system-test@example.invalid"]);
|
|
119
|
+
await gitExec(root, ["config", "user.name", "system-test"]);
|
|
120
|
+
await gitExec(root, ["config", "commit.gpgsign", "false"]);
|
|
121
|
+
await writeFile(path.join(root, "forge.yaml"), 'schema: "forge/workspace@1"\n');
|
|
122
|
+
await writeFile(path.join(root, "seed.txt"), "seed\n");
|
|
123
|
+
await gitExec(root, ["add", "-A"]);
|
|
124
|
+
const seed = await gitExec(root, ["commit", "-m", "seed"]);
|
|
125
|
+
if (seed.exitCode !== 0) throw new Error(`seed commit failed: ${seed.stderr}`);
|
|
126
|
+
const develop = await gitExec(root, ["branch", "develop"]);
|
|
127
|
+
if (develop.exitCode !== 0) throw new Error(`develop branch failed: ${develop.stderr}`);
|
|
128
|
+
// flow.integrate requires the primary checkout to sit on develop.
|
|
129
|
+
const checkout = await gitExec(root, ["checkout", "develop"]);
|
|
130
|
+
if (checkout.exitCode !== 0) throw new Error(`develop checkout failed: ${checkout.stderr}`);
|
|
131
|
+
return root;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** products.local.yaml entry pointing at an absolute product checkout. */
|
|
135
|
+
export function localMapFor(entries: Record<string, string>, launcherArgv?: string[]): string {
|
|
136
|
+
const folders = Object.entries(entries)
|
|
137
|
+
.map(([id, folder]) => ` ${id}: ${JSON.stringify(folder)}`)
|
|
138
|
+
.join("\n");
|
|
139
|
+
const launcher = launcherArgv
|
|
140
|
+
? `launcher:\n argv: [${launcherArgv.map((a) => JSON.stringify(a)).join(", ")}]\n`
|
|
141
|
+
: "";
|
|
142
|
+
return `schema: forge/system-products-local@1\nfolders:\n${folders}\n${launcher}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A minimal forge/system-task@1 file content for fixture seeding. */
|
|
146
|
+
export function taskYaml(overrides: Record<string, unknown> = {}): string {
|
|
147
|
+
const base: Record<string, unknown> = {
|
|
148
|
+
schema: "forge/system-task@1",
|
|
149
|
+
id: "T-0001",
|
|
150
|
+
title: "fixture task",
|
|
151
|
+
product: "alpha",
|
|
152
|
+
slug: "fixture-task",
|
|
153
|
+
kind: "change",
|
|
154
|
+
state: "proposed",
|
|
155
|
+
origin: { kind: "operator", ref: null },
|
|
156
|
+
contracts: [],
|
|
157
|
+
dependsOn: [],
|
|
158
|
+
brief: "queue/briefs/T-0001.md",
|
|
159
|
+
briefSha256: null,
|
|
160
|
+
dispatch: null,
|
|
161
|
+
report: null,
|
|
162
|
+
integratedCommit: null,
|
|
163
|
+
history: [{ at: "2026-01-01T00:00:00Z", from: "none", to: "proposed", by: "operator" }],
|
|
164
|
+
...overrides,
|
|
165
|
+
};
|
|
166
|
+
const yaml = Object.entries(base)
|
|
167
|
+
.map(([k, v]) => `${k}: ${typeof v === "string" ? v : JSON.stringify(v)}`)
|
|
168
|
+
.join("\n");
|
|
169
|
+
return `${yaml}\n`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A ready-state dispatch brief with a real goal. */
|
|
173
|
+
export function readyBrief(taskId = "T-0001", product = "alpha"): string {
|
|
174
|
+
return `---
|
|
175
|
+
schema: forge/dispatch-brief@1
|
|
176
|
+
task: ${taskId}
|
|
177
|
+
product: ${product}
|
|
178
|
+
goal: "prove the dispatch pipeline end to end"
|
|
179
|
+
acceptance:
|
|
180
|
+
- claim: "the branch exists"
|
|
181
|
+
check: "git branch --list auto/task-*"
|
|
182
|
+
constraints: []
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
# ${taskId}
|
|
186
|
+
|
|
187
|
+
prove the dispatch pipeline end to end
|
|
188
|
+
`;
|
|
189
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>Tests for outbox.validate (RFC-1510): absent docs/outbox passes
|
|
4
|
+
(AC-1), schema violations OUTBOX-01 (AC-2), filename-stem binding OUTBOX-02
|
|
5
|
+
(AC-3) and profile-agnostic behavior — never SYSTEM-01 (AC-4).</purpose>
|
|
6
|
+
<non-goals><item>System-side scan coverage lives in system-outbox-scan.test.ts.</item></non-goals>
|
|
7
|
+
</MODULE_CONTRACT>
|
|
8
|
+
<CHANGE_SUMMARY>
|
|
9
|
+
<item>RFC-1510: step 1 — outbox.validate tests</item>
|
|
10
|
+
<item>RFC-1510: implement RFC-1510 — product outbox for dependency-contract requests</item>
|
|
11
|
+
</CHANGE_SUMMARY>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// @vitest-environment node
|
|
15
|
+
|
|
16
|
+
import { describe, expect, it } from "vitest";
|
|
17
|
+
import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
|
|
18
|
+
import os from "node:os";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
|
|
21
|
+
import { runOutboxValidate } from "../handlers/outbox-validate.ts";
|
|
22
|
+
import { makeContext, makeSystemRepo } from "./helpers.ts";
|
|
23
|
+
|
|
24
|
+
function input() {
|
|
25
|
+
return { argv: [], flags: {} };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const VALID_ENTRY = `schema: forge/outbox@1
|
|
29
|
+
id: OB-0001
|
|
30
|
+
contract: alpha-contract
|
|
31
|
+
need: "a stable consumer surface"
|
|
32
|
+
why: "our product composes it"
|
|
33
|
+
state: open
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
async function makeRepo(files: Record<string, string>): Promise<string> {
|
|
37
|
+
const root = await mkdtemp(path.join(os.tmpdir(), "forge-outbox-"));
|
|
38
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
39
|
+
const abs = path.join(root, rel);
|
|
40
|
+
await mkdir(path.dirname(abs), { recursive: true });
|
|
41
|
+
await writeFile(abs, content);
|
|
42
|
+
}
|
|
43
|
+
return root;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe("outbox.validate", () => {
|
|
47
|
+
it("AC-1: a repository without docs/outbox/ exits 0", async () => {
|
|
48
|
+
const root = await makeRepo({ "forge.yaml": "profile: typescript\n" });
|
|
49
|
+
const result = await runOutboxValidate(input(), makeContext(root));
|
|
50
|
+
expect(result.exitCode).toBe(0);
|
|
51
|
+
expect(result.data?.checked).toBe(0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("AC-2: an entry failing forge/outbox@1 refuses OUTBOX-01", async () => {
|
|
55
|
+
const root = await makeRepo({
|
|
56
|
+
"forge.yaml": "profile: typescript\n",
|
|
57
|
+
"docs/outbox/OB-0001.yaml": VALID_ENTRY.replace("state: open", "state: bogus"),
|
|
58
|
+
});
|
|
59
|
+
const result = await runOutboxValidate(input(), makeContext(root));
|
|
60
|
+
expect(result.exitCode).toBe(1);
|
|
61
|
+
expect(result.data?.diagnostics.some((d) => d.ruleId === "OUTBOX-01")).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("AC-3: an entry whose id differs from the filename stem refuses OUTBOX-02", async () => {
|
|
65
|
+
const root = await makeRepo({
|
|
66
|
+
"forge.yaml": "profile: typescript\n",
|
|
67
|
+
"docs/outbox/OB-0002.yaml": VALID_ENTRY, // declares id OB-0001
|
|
68
|
+
});
|
|
69
|
+
const result = await runOutboxValidate(input(), makeContext(root));
|
|
70
|
+
expect(result.exitCode).toBe(1);
|
|
71
|
+
expect(result.data?.diagnostics.some((d) => d.ruleId === "OUTBOX-02")).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("AC-4: a non-system profile never reports SYSTEM-01", async () => {
|
|
75
|
+
const root = await makeRepo({
|
|
76
|
+
"forge.yaml": "profile: typescript\n",
|
|
77
|
+
"docs/outbox/OB-0001.yaml": VALID_ENTRY,
|
|
78
|
+
});
|
|
79
|
+
const result = await runOutboxValidate(input(), makeContext(root));
|
|
80
|
+
expect(result.exitCode).toBe(0);
|
|
81
|
+
expect(result.data?.diagnostics.some((d) => d.ruleId === "SYSTEM-01")).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("a valid entry passes inside a system repository too", async () => {
|
|
85
|
+
const root = await makeSystemRepo({
|
|
86
|
+
"docs/outbox/OB-0001.yaml": VALID_ENTRY,
|
|
87
|
+
});
|
|
88
|
+
const result = await runOutboxValidate(input(), makeContext(root));
|
|
89
|
+
expect(result.exitCode).toBe(0);
|
|
90
|
+
expect(result.data?.checked).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
});
|