@markjaquith/agency 2.8.0 → 2.10.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/README.md +79 -0
- package/cli.ts +50 -4
- package/fixtures/protocol/error.json +14 -0
- package/fixtures/protocol/success.json +7 -0
- package/index.ts +1 -0
- package/package.json +16 -1
- package/schemas/agency-envelope-v1.schema.json +38 -0
- package/src/cli-parser.test.ts +10 -0
- package/src/cli-parser.ts +26 -1
- package/src/cli.test.ts +68 -1
- package/src/commands/context.test.ts +379 -0
- package/src/commands/context.ts +29 -0
- package/src/commands/read-only.test.ts +8 -0
- package/src/commands/validate.ts +7 -0
- package/src/commands/work.test.ts +3 -3
- package/src/protocol.test.ts +87 -0
- package/src/protocol.ts +217 -0
- package/src/services/ContextService.ts +898 -0
- package/src/services/WorktreeService.test.ts +2 -2
- package/src/test-utils.ts +12 -3
- package/src/utils/effect.test.ts +9 -3
- package/src/utils/effect.ts +4 -2
|
@@ -3,7 +3,7 @@ import { Effect } from "effect"
|
|
|
3
3
|
import { mkdir, rm } from "node:fs/promises"
|
|
4
4
|
import { join } from "node:path"
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
captureErrors,
|
|
7
7
|
cleanupTempDir,
|
|
8
8
|
createTempDir,
|
|
9
9
|
runTestEffect,
|
|
@@ -287,7 +287,7 @@ describe("WorktreeService", () => {
|
|
|
287
287
|
),
|
|
288
288
|
)
|
|
289
289
|
|
|
290
|
-
const logs = await
|
|
290
|
+
const logs = await captureErrors(() =>
|
|
291
291
|
runTestEffect(
|
|
292
292
|
WorktreeService.pipe(
|
|
293
293
|
Effect.flatMap((service) =>
|
package/src/test-utils.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { WorktreeService } from "./services/WorktreeService"
|
|
|
13
13
|
import { PullRequestService } from "./services/PullRequestService"
|
|
14
14
|
import { ArchiveService } from "./services/ArchiveService"
|
|
15
15
|
import { IntegrationService } from "./services/IntegrationService"
|
|
16
|
+
import { ContextService } from "./services/ContextService"
|
|
16
17
|
|
|
17
18
|
export const createTempDir = () => mkdtemp(join(tmpdir(), "agency-test-"))
|
|
18
19
|
|
|
@@ -30,6 +31,7 @@ const TestLayer = Layer.mergeAll(
|
|
|
30
31
|
PullRequestService.Default,
|
|
31
32
|
ArchiveService.Default,
|
|
32
33
|
IntegrationService.Default,
|
|
34
|
+
ContextService.Default,
|
|
33
35
|
)
|
|
34
36
|
|
|
35
37
|
export async function runTestEffect<A, E>(
|
|
@@ -45,17 +47,24 @@ export async function runTestEffect<A, E>(
|
|
|
45
47
|
return Effect.runPromise(program)
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
async function captureConsole(
|
|
51
|
+
method: "log" | "error",
|
|
49
52
|
run: () => Promise<unknown>,
|
|
50
53
|
): Promise<string[]> {
|
|
51
54
|
const logs: string[] = []
|
|
52
|
-
const
|
|
55
|
+
const output = spyOn(console, method).mockImplementation((...args) => {
|
|
53
56
|
logs.push(args.join(" "))
|
|
54
57
|
})
|
|
55
58
|
try {
|
|
56
59
|
await run()
|
|
57
60
|
return logs
|
|
58
61
|
} finally {
|
|
59
|
-
|
|
62
|
+
output.mockRestore()
|
|
60
63
|
}
|
|
61
64
|
}
|
|
65
|
+
|
|
66
|
+
export const captureLogs = (run: () => Promise<unknown>) =>
|
|
67
|
+
captureConsole("log", run)
|
|
68
|
+
|
|
69
|
+
export const captureErrors = (run: () => Promise<unknown>) =>
|
|
70
|
+
captureConsole("error", run)
|
package/src/utils/effect.test.ts
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
1
|
+
import { describe, expect, spyOn, test } from "bun:test"
|
|
2
2
|
import { captureLogs } from "../test-utils"
|
|
3
3
|
import { createLoggers } from "./effect"
|
|
4
4
|
|
|
5
5
|
describe("createLoggers", () => {
|
|
6
6
|
test("keeps JSON output machine-readable when verbose is enabled", async () => {
|
|
7
|
+
const errors: string[] = []
|
|
8
|
+
const error = spyOn(console, "error").mockImplementation((...args) => {
|
|
9
|
+
errors.push(args.join(" "))
|
|
10
|
+
})
|
|
7
11
|
const logs = await captureLogs(async () => {
|
|
8
12
|
const { log, verboseLog } = createLoggers({ json: true, verbose: true })
|
|
9
13
|
verboseLog("debug")
|
|
10
14
|
log('{"ok":true}')
|
|
11
15
|
})
|
|
16
|
+
error.mockRestore()
|
|
12
17
|
|
|
13
18
|
expect(logs).toEqual(['{"ok":true}'])
|
|
19
|
+
expect(errors).toEqual(["debug"])
|
|
14
20
|
})
|
|
15
21
|
|
|
16
|
-
test("lets
|
|
22
|
+
test("lets JSON output override silent", async () => {
|
|
17
23
|
const logs = await captureLogs(async () => {
|
|
18
24
|
const { log } = createLoggers({ json: true, silent: true })
|
|
19
25
|
log('{"ok":true}')
|
|
20
26
|
})
|
|
21
27
|
|
|
22
|
-
expect(logs).toEqual([])
|
|
28
|
+
expect(logs).toEqual(['{"ok":true}'])
|
|
23
29
|
})
|
|
24
30
|
})
|
package/src/utils/effect.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { emitCommandResult } from "../protocol"
|
|
2
|
+
|
|
1
3
|
export function createLoggers(options: {
|
|
2
4
|
readonly silent?: boolean
|
|
3
5
|
readonly verbose?: boolean
|
|
@@ -5,7 +7,7 @@ export function createLoggers(options: {
|
|
|
5
7
|
}) {
|
|
6
8
|
const { silent = false, verbose = false, json = false } = options
|
|
7
9
|
return {
|
|
8
|
-
log: silent ? () => {} : console.log,
|
|
9
|
-
verboseLog: verbose && !silent
|
|
10
|
+
log: json ? emitCommandResult : silent ? () => {} : console.log,
|
|
11
|
+
verboseLog: verbose && !silent ? console.error : () => {},
|
|
10
12
|
}
|
|
11
13
|
}
|