@markjaquith/agency 3.2.13 → 3.2.15

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.
Files changed (69) hide show
  1. package/package.json +7 -2
  2. package/src/workbase/schemas.ts +12 -0
  3. package/fixtures/protocol/orchestration-recipes.json +0 -53
  4. package/pi-extensions/agency.test.ts +0 -117
  5. package/src/check-commits.test.ts +0 -58
  6. package/src/cli-parser.test.ts +0 -945
  7. package/src/cli.test.ts +0 -1889
  8. package/src/commands/act.test.ts +0 -418
  9. package/src/commands/archive.test.ts +0 -236
  10. package/src/commands/context.test.ts +0 -665
  11. package/src/commands/description.test.ts +0 -103
  12. package/src/commands/doctor.test.ts +0 -185
  13. package/src/commands/epic.test.ts +0 -196
  14. package/src/commands/init.test.ts +0 -117
  15. package/src/commands/integration.test.ts +0 -165
  16. package/src/commands/pr.test.ts +0 -248
  17. package/src/commands/push.test.ts +0 -56
  18. package/src/commands/read-only.test.ts +0 -161
  19. package/src/commands/repo.test.ts +0 -199
  20. package/src/commands/restore.test.ts +0 -106
  21. package/src/commands/status.test.ts +0 -113
  22. package/src/commands/sync.test.ts +0 -200
  23. package/src/commands/task-phase.test.ts +0 -410
  24. package/src/commands/task.test.ts +0 -281
  25. package/src/commands/validate.test.ts +0 -186
  26. package/src/commands/work.test.ts +0 -1375
  27. package/src/commands/workbase.test.ts +0 -170
  28. package/src/graph-schema.test.ts +0 -124
  29. package/src/protocol.test.ts +0 -163
  30. package/src/readiness.test.ts +0 -105
  31. package/src/services/ArchiveBulkService.test.ts +0 -384
  32. package/src/services/ArchiveService.test.ts +0 -1092
  33. package/src/services/EpicService.test.ts +0 -74
  34. package/src/services/FileSystemService.test.ts +0 -81
  35. package/src/services/GraphMutationService.test.ts +0 -486
  36. package/src/services/GraphService.test.ts +0 -494
  37. package/src/services/IntegrationService.test.ts +0 -1091
  38. package/src/services/LifecycleTransaction.test.ts +0 -145
  39. package/src/services/PullRequestService.test.ts +0 -716
  40. package/src/services/PushService.test.ts +0 -408
  41. package/src/services/ReadinessService.test.ts +0 -290
  42. package/src/services/RepositoryService.test.ts +0 -789
  43. package/src/services/ReviewService.test.ts +0 -408
  44. package/src/services/SyncService.test.ts +0 -1377
  45. package/src/services/TaskPhaseService.test.ts +0 -852
  46. package/src/services/VersionControlService.test.ts +0 -62
  47. package/src/services/WorkbaseService.test.ts +0 -910
  48. package/src/services/WorktreeLock.test.ts +0 -205
  49. package/src/services/WorktreePerformance.test.ts +0 -71
  50. package/src/services/WorktreeService.test.ts +0 -2292
  51. package/src/test-utils.ts +0 -110
  52. package/src/usage-log.test.ts +0 -188
  53. package/src/utils/chooser.test.ts +0 -192
  54. package/src/utils/effect.test.ts +0 -30
  55. package/src/utils/interactive.pty.test.ts +0 -128
  56. package/src/utils/interactive.test.tsx +0 -860
  57. package/src/utils/process.test.ts +0 -132
  58. package/src/utils/progress.test.ts +0 -37
  59. package/src/work-view.test.ts +0 -151
  60. package/src/workbase/agent-command.test.ts +0 -128
  61. package/src/workbase/checkout-command.test.ts +0 -62
  62. package/src/workbase/delivery-command.test.ts +0 -180
  63. package/src/workbase/dependency-graph.test.ts +0 -50
  64. package/src/workbase/execution-contract.test.ts +0 -161
  65. package/src/workbase/frontmatter.test.ts +0 -67
  66. package/src/workbase/repository-reference.test.ts +0 -25
  67. package/src/workbase/schemas.test.ts +0 -543
  68. package/src/workbase/work-target.test.ts +0 -108
  69. package/src/workbase/worktree-command.test.ts +0 -61
@@ -1,170 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
- import { join } from "node:path"
3
- import {
4
- captureLogs,
5
- cleanupTempDir,
6
- createTempDir,
7
- runTestEffect,
8
- } from "../test-utils"
9
- import { workbase } from "./workbase"
10
-
11
- describe("workbase command", () => {
12
- let root: string
13
- let configDirectory: string
14
-
15
- beforeEach(async () => {
16
- root = await createTempDir()
17
- configDirectory = join(root, "config")
18
- await Bun.write(join(root, "agency.json"), '{"version":2}\n')
19
- })
20
-
21
- afterEach(async () => cleanupTempDir(root))
22
-
23
- test("adds and lists workbases as JSON", async () => {
24
- const added = await captureLogs(() =>
25
- runTestEffect(
26
- workbase({
27
- subcommand: "add",
28
- args: [root],
29
- configDirectory,
30
- json: true,
31
- }),
32
- ),
33
- )
34
- const registration = JSON.parse(added[0]!)
35
-
36
- const listed = await captureLogs(() =>
37
- runTestEffect(
38
- workbase({
39
- subcommand: "list",
40
- args: [],
41
- configDirectory,
42
- json: true,
43
- }),
44
- ),
45
- )
46
-
47
- expect(JSON.parse(listed[0]!)).toEqual({
48
- workbases: [registration],
49
- })
50
- })
51
-
52
- test("sets, clears, and removes the default workbase", async () => {
53
- const added = await captureLogs(() =>
54
- runTestEffect(
55
- workbase({
56
- subcommand: "add",
57
- args: [root],
58
- name: "primary",
59
- configDirectory,
60
- json: true,
61
- }),
62
- ),
63
- )
64
- const registration = JSON.parse(added[0]!)
65
-
66
- await runTestEffect(
67
- workbase({
68
- subcommand: "default",
69
- args: ["primary"],
70
- configDirectory,
71
- silent: true,
72
- }),
73
- )
74
- const listed = await captureLogs(() =>
75
- runTestEffect(
76
- workbase({
77
- subcommand: "list",
78
- args: [],
79
- configDirectory,
80
- json: true,
81
- }),
82
- ),
83
- )
84
- expect(JSON.parse(listed[0]!).defaultId).toBe(registration.id)
85
- await runTestEffect(
86
- workbase({
87
- subcommand: "default",
88
- args: [],
89
- clear: true,
90
- configDirectory,
91
- silent: true,
92
- }),
93
- )
94
- expect(
95
- await Bun.file(join(configDirectory, "agency/workbases.json")).json(),
96
- ).toEqual({ version: 2, workbases: [registration] })
97
-
98
- await runTestEffect(
99
- workbase({
100
- subcommand: "remove",
101
- args: [registration.id],
102
- configDirectory,
103
- silent: true,
104
- }),
105
- )
106
- expect(
107
- await Bun.file(join(configDirectory, "agency/workbases.json")).json(),
108
- ).toEqual({ version: 2, workbases: [] })
109
- })
110
-
111
- test("names, shows, and clears a workbase name", async () => {
112
- const added = await captureLogs(() =>
113
- runTestEffect(
114
- workbase({
115
- subcommand: "add",
116
- args: [root],
117
- configDirectory,
118
- json: true,
119
- }),
120
- ),
121
- )
122
- const registration = JSON.parse(added[0]!)
123
- await runTestEffect(
124
- workbase({
125
- subcommand: "name",
126
- args: [registration.id, "primary"],
127
- configDirectory,
128
- silent: true,
129
- }),
130
- )
131
-
132
- const shown = await captureLogs(() =>
133
- runTestEffect(
134
- workbase({
135
- subcommand: "show",
136
- args: ["primary"],
137
- configDirectory,
138
- json: true,
139
- }),
140
- ),
141
- )
142
- expect(JSON.parse(shown[0]!).name).toBe("primary")
143
-
144
- await runTestEffect(
145
- workbase({
146
- subcommand: "name",
147
- args: [registration.id],
148
- clear: true,
149
- configDirectory,
150
- silent: true,
151
- }),
152
- )
153
- expect(
154
- await Bun.file(join(configDirectory, "agency/workbases.json")).json(),
155
- ).toEqual({ version: 2, workbases: [registration] })
156
- })
157
-
158
- test("requires an add path", async () => {
159
- await expect(
160
- runTestEffect(
161
- workbase({
162
- subcommand: "add",
163
- args: [],
164
- configDirectory,
165
- silent: true,
166
- }),
167
- ),
168
- ).rejects.toThrow("Usage: agency workbase add <path>")
169
- })
170
- })
@@ -1,124 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { Schema } from "@effect/schema"
3
- import jsonSchema from "../schemas/agency-graph-v1.schema.json"
4
- import { AgencyGraph, graphJsonlRecords } from "./graph-schema"
5
-
6
- describe("graph contract", () => {
7
- test("publishes the v1 JSON Schema", () => {
8
- expect(jsonSchema).toMatchObject({
9
- $schema: "https://json-schema.org/draft/2020-12/schema",
10
- title: "Agency workbase graph v1",
11
- properties: { version: { const: 1 } },
12
- })
13
- expect(jsonSchema.properties.filters).toMatchObject({
14
- additionalProperties: false,
15
- required: ["ready", "blocked", "statuses", "repositories", "kinds"],
16
- })
17
- expect(jsonSchema.$defs.node.allOf).toHaveLength(5)
18
- expect(jsonSchema.$defs.readiness.required).toEqual([
19
- "ready",
20
- "blocked",
21
- "blockedBy",
22
- "terminal",
23
- "blockers",
24
- ])
25
- expect(jsonSchema.$defs.node.allOf[3]?.then?.properties).toMatchObject({
26
- status: { type: "null" },
27
- readiness: { type: "null" },
28
- aggregate: { type: "null" },
29
- })
30
- expect(jsonSchema.$defs.taskHandoff).toMatchObject({
31
- additionalProperties: false,
32
- required: ["source", "sourceRevision"],
33
- })
34
- expect(jsonSchema.$defs.singleTaskData.properties).toMatchObject({
35
- purpose: { $ref: "#/$defs/taskPurpose" },
36
- handoff: { $ref: "#/$defs/taskHandoff" },
37
- })
38
- })
39
-
40
- test("streams records that reconstruct graph semantics", () => {
41
- const nodes = [
42
- {
43
- id: "repository:agency",
44
- key: "agency",
45
- kind: "repository" as const,
46
- dependents: ["repository:effect"],
47
- repositories: ["agency"],
48
- status: null,
49
- readiness: null,
50
- aggregate: null,
51
- data: { alias: "agency" },
52
- },
53
- {
54
- id: "repository:effect",
55
- key: "effect",
56
- kind: "repository" as const,
57
- dependents: [],
58
- repositories: ["effect"],
59
- status: null,
60
- readiness: null,
61
- aggregate: null,
62
- data: { alias: "effect" },
63
- },
64
- ]
65
- const edges = [
66
- {
67
- id: "references:repository:agency:repository:effect",
68
- kind: "references" as const,
69
- from: "repository:agency",
70
- to: "repository:effect",
71
- },
72
- ]
73
- const graph = {
74
- version: 1,
75
- workbase: { version: 2, vcs: "git" },
76
- filters: {
77
- ready: null,
78
- blocked: null,
79
- statuses: [],
80
- repositories: [],
81
- kinds: [],
82
- },
83
- includes: [],
84
- nodes,
85
- edges,
86
- summary: {
87
- status: "open",
88
- total: 0,
89
- open: 0,
90
- working: 0,
91
- delegated: 0,
92
- done: 0,
93
- dropped: 0,
94
- terminal: 0,
95
- },
96
- validation: { valid: true, issues: [] },
97
- } satisfies AgencyGraph
98
- expect(
99
- Schema.decodeUnknownSync(AgencyGraph, { onExcessProperty: "error" })(
100
- graph,
101
- ),
102
- ).toEqual(graph)
103
- const records = [...graphJsonlRecords(graph)]
104
- const { nodes: _nodes, edges: _edges, ...metadata } = graph
105
- expect(records).toEqual([
106
- {
107
- version: 1,
108
- type: "meta",
109
- graph: metadata,
110
- },
111
- ...nodes.map((node) => ({
112
- version: 1 as const,
113
- type: "node" as const,
114
- node,
115
- })),
116
- ...edges.map((edge) => ({
117
- version: 1 as const,
118
- type: "edge" as const,
119
- edge,
120
- })),
121
- { version: 1, type: "end", nodeCount: 2, edgeCount: 1 },
122
- ])
123
- })
124
- })
@@ -1,163 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { Schema } from "@effect/schema"
3
- import errorFixture from "../fixtures/protocol/error.json"
4
- import successFixture from "../fixtures/protocol/success.json"
5
- import jsonSchema from "../schemas/agency-envelope-v1.schema.json"
6
- import {
7
- AgencyEnvelope,
8
- collectCommandResult,
9
- emitCommandResult,
10
- errorEnvelope,
11
- successEnvelope,
12
- } from "./protocol"
13
-
14
- describe("machine protocol", () => {
15
- test("accepts the representative success and error fixtures", () => {
16
- for (const fixture of [successFixture, errorFixture]) {
17
- const decoded = Schema.decodeUnknownSync(AgencyEnvelope, {
18
- onExcessProperty: "error",
19
- })(fixture)
20
- expect(JSON.stringify(decoded)).toBe(JSON.stringify(fixture))
21
- }
22
- })
23
-
24
- test("publishes the matching v1 JSON Schema", () => {
25
- expect(jsonSchema).toMatchObject({
26
- $schema: "https://json-schema.org/draft/2020-12/schema",
27
- title: "Agency machine result envelope v1",
28
- oneOf: [
29
- { properties: { version: { const: 1 }, ok: { const: true } } },
30
- { properties: { version: { const: 1 }, ok: { const: false } } },
31
- ],
32
- })
33
- })
34
-
35
- test("collects one command result without writing it", async () => {
36
- const result = await collectCommandResult(async () => {
37
- emitCommandResult('{"value":42}')
38
- })
39
- expect(successEnvelope(result)).toEqual({
40
- version: 1,
41
- ok: true,
42
- result: { value: 42 },
43
- })
44
- expect(successEnvelope(undefined).result).toBeNull()
45
- })
46
-
47
- test("rejects commands that emit multiple machine results", async () => {
48
- await expect(
49
- collectCommandResult(async () => {
50
- emitCommandResult("first")
51
- emitCommandResult("second")
52
- }),
53
- ).rejects.toThrow("more than one result")
54
- })
55
-
56
- test("restores collection state after a command throws", async () => {
57
- const originalLog = console.log
58
- await expect(
59
- collectCommandResult(async () => {
60
- emitCommandResult("partial")
61
- throw new Error("command failed")
62
- }),
63
- ).rejects.toThrow("command failed")
64
- expect(console.log).toBe(originalLog)
65
-
66
- await expect(
67
- collectCommandResult(async () => {
68
- emitCommandResult("recovered")
69
- }),
70
- ).resolves.toBe("recovered")
71
- })
72
-
73
- test("rejects nested result collectors without disrupting the outer one", async () => {
74
- const result = await collectCommandResult(async () => {
75
- await expect(collectCommandResult(async () => {})).rejects.toThrow(
76
- "already active",
77
- )
78
- emitCommandResult("outer")
79
- })
80
-
81
- expect(result).toBe("outer")
82
- })
83
-
84
- test("normalizes unknown failures into stable error details", () => {
85
- expect(errorEnvelope(new Error("boom"))).toEqual({
86
- version: 1,
87
- ok: false,
88
- error: {
89
- code: "COMMAND_FAILED",
90
- message: "boom",
91
- fields: {},
92
- retryable: false,
93
- },
94
- })
95
- })
96
-
97
- test("preserves relevant fields from classified errors", () => {
98
- const validation = errorEnvelope({
99
- _tag: "ValidationFailedError",
100
- message: "invalid workbase",
101
- cause: new Error("private cause"),
102
- optional: undefined,
103
- root: "/work/agency",
104
- issues: [{ path: "TASK.md", message: "invalid status" }],
105
- })
106
- expect(validation).toMatchObject({
107
- error: {
108
- code: "VALIDATION_FAILED",
109
- fields: {
110
- root: "/work/agency",
111
- issues: [{ path: "TASK.md", message: "invalid status" }],
112
- },
113
- },
114
- })
115
- expect(Object.keys(validation.error.fields).sort()).toEqual([
116
- "issues",
117
- "root",
118
- ])
119
- expect(
120
- errorEnvelope({
121
- _tag: "RevisionConflictError",
122
- message: "revision conflict",
123
- path: "tasks/example/TASK.md",
124
- expectedRevision: "a".repeat(64),
125
- currentRevision: "b".repeat(64),
126
- }),
127
- ).toMatchObject({
128
- error: {
129
- code: "REVISION_CONFLICT",
130
- retryable: true,
131
- fields: {
132
- path: "tasks/example/TASK.md",
133
- expectedRevision: "a".repeat(64),
134
- currentRevision: "b".repeat(64),
135
- },
136
- },
137
- })
138
- })
139
-
140
- test("uses dynamic protocol metadata without duplicating it in fields", () => {
141
- expect(
142
- errorEnvelope({
143
- _tag: "PushError",
144
- message: "remote timed out",
145
- protocolCode: "PUSH_TIMEOUT",
146
- retryable: true,
147
- remediation: "Retry after checking connectivity.",
148
- category: "timeout",
149
- stage: "fetch",
150
- }),
151
- ).toEqual({
152
- version: 1,
153
- ok: false,
154
- error: {
155
- code: "PUSH_TIMEOUT",
156
- message: "remote timed out",
157
- fields: { category: "timeout", stage: "fetch" },
158
- retryable: true,
159
- remediation: "Retry after checking connectivity.",
160
- },
161
- })
162
- })
163
- })
@@ -1,105 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import {
3
- WORK_STATUS_TRANSITIONS,
4
- aggregateProgress,
5
- canTransitionStatus,
6
- isDependencySatisfied,
7
- isTerminalStatus,
8
- readinessState,
9
- } from "./readiness"
10
- import type { WorkStatus } from "./workbase/schemas"
11
-
12
- const statuses: readonly WorkStatus[] = [
13
- "open",
14
- "working",
15
- "delegated",
16
- "done",
17
- "dropped",
18
- ]
19
-
20
- describe("readiness model", () => {
21
- test("only done satisfies dependencies and terminal states remain distinct", () => {
22
- expect(isDependencySatisfied("done")).toBe(true)
23
- expect(isDependencySatisfied("dropped")).toBe(false)
24
- expect(readinessState("done", [{ id: "task:one" }])).toEqual({
25
- ready: false,
26
- blocked: true,
27
- blockedBy: ["task:one"],
28
- terminal: true,
29
- })
30
- expect(readinessState("working", [{ id: "dependency:self" }])).toEqual({
31
- ready: false,
32
- blocked: true,
33
- blockedBy: ["dependency:self"],
34
- terminal: false,
35
- })
36
- })
37
-
38
- test("classifies every status and dependency state", () => {
39
- expect(statuses.map(isTerminalStatus)).toEqual([
40
- false,
41
- false,
42
- false,
43
- true,
44
- true,
45
- ])
46
- expect([...statuses, undefined].map(isDependencySatisfied)).toEqual([
47
- false,
48
- false,
49
- false,
50
- true,
51
- false,
52
- false,
53
- ])
54
- })
55
-
56
- test("covers the complete status transition matrix", () => {
57
- for (const from of statuses) {
58
- for (const to of statuses) {
59
- expect(canTransitionStatus(from, to), `${from} -> ${to}`).toBe(
60
- WORK_STATUS_TRANSITIONS[from].includes(to as never),
61
- )
62
- }
63
- }
64
- })
65
-
66
- test("rolls every status-precedence branch into aggregate progress", () => {
67
- const cases: readonly [readonly WorkStatus[], WorkStatus][] = [
68
- [[], "open"],
69
- [["done", "done"], "done"],
70
- [["done", "dropped"], "dropped"],
71
- [["open", "working", "delegated"], "working"],
72
- [["open", "delegated"], "delegated"],
73
- [["open", "done"], "open"],
74
- ]
75
-
76
- for (const [input, status] of cases) {
77
- const result = aggregateProgress(input)
78
- expect(result.status, input.join(",") || "empty").toBe(status)
79
- expect(result.total).toBe(input.length)
80
- expect(result.terminal).toBe(
81
- input.filter((value) => value === "done" || value === "dropped").length,
82
- )
83
- for (const value of statuses) {
84
- expect(result[value]).toBe(
85
- input.filter((candidate) => candidate === value).length,
86
- )
87
- }
88
- }
89
- })
90
-
91
- test("deduplicates and sorts blockers while honoring explicit readiness", () => {
92
- expect(
93
- readinessState(
94
- "open",
95
- [{ id: "task:z" }, { id: "task:a" }, { id: "task:z" }],
96
- true,
97
- ),
98
- ).toEqual({
99
- ready: true,
100
- blocked: false,
101
- blockedBy: ["task:a", "task:z"],
102
- terminal: false,
103
- })
104
- })
105
- })