@arcforge/platform 2.0.166
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 +31 -0
- package/package.json +69 -0
- package/src/bin/supervisor.ts +102 -0
- package/src/bin/test-api.ts +30 -0
- package/src/bin/test-preload.ts +308 -0
- package/src/bin/update-helper.ts +32 -0
- package/src/build/bench/CLAUDE.md +106 -0
- package/src/build/bench/SPEC.md +209 -0
- package/src/build/bench/agents.ts +105 -0
- package/src/build/bench/axes.ts +84 -0
- package/src/build/bench/bench.ts +96 -0
- package/src/build/bench/discover.ts +147 -0
- package/src/build/bench/index.ts +7 -0
- package/src/build/bench/log.ts +47 -0
- package/src/build/bench/matrix.ts +23 -0
- package/src/build/bench/preload.ts +440 -0
- package/src/build/bench/prepare.ts +61 -0
- package/src/build/bench/projection.ts +112 -0
- package/src/build/bench/resolve.ts +54 -0
- package/src/build/bench/runner.ts +309 -0
- package/src/build/bench/schema/extract.ts +148 -0
- package/src/build/bench/schema/index.ts +2 -0
- package/src/build/bench/schema/schema.ts +95 -0
- package/src/build/bench/schema/worker.ts +30 -0
- package/src/build/bench/typegen.ts +119 -0
- package/src/build/bench/workspace/files.ts +139 -0
- package/src/build/bench/workspace/handle.ts +133 -0
- package/src/build/bench/workspace/index.ts +11 -0
- package/src/build/bench/workspace/workspace.ts +14 -0
- package/src/build/blueprint/blueprint.ts +398 -0
- package/src/build/blueprint/cognet/abi.ts +207 -0
- package/src/build/blueprint/cognet/bundle-worker.ts +93 -0
- package/src/build/blueprint/cognet/bundle.ts +664 -0
- package/src/build/blueprint/cognet/cognet.ts +249 -0
- package/src/build/blueprint/cognet/index.ts +10 -0
- package/src/build/blueprint/cognet/manifest.ts +38 -0
- package/src/build/blueprint/cognet/resolve.ts +113 -0
- package/src/build/blueprint/collisions.ts +51 -0
- package/src/build/blueprint/index.ts +29 -0
- package/src/build/blueprint/modules/entries.ts +117 -0
- package/src/build/blueprint/modules/index.ts +300 -0
- package/src/build/blueprint/modules/meta.ts +174 -0
- package/src/build/blueprint/scan/boot.ts +34 -0
- package/src/build/blueprint/scan/cognetImports.ts +56 -0
- package/src/build/blueprint/scan/components.ts +45 -0
- package/src/build/blueprint/scan/config.ts +234 -0
- package/src/build/blueprint/scan/configImports.ts +232 -0
- package/src/build/blueprint/scan/declare-worker.ts +61 -0
- package/src/build/blueprint/scan/declare.ts +393 -0
- package/src/build/blueprint/scan/h3-globals.ts +137 -0
- package/src/build/blueprint/scan/knowledge.ts +101 -0
- package/src/build/blueprint/scan/middleware.ts +110 -0
- package/src/build/blueprint/scan/moduleImports.ts +79 -0
- package/src/build/blueprint/scan/plugins.ts +93 -0
- package/src/build/blueprint/scan/promptPackages.ts +45 -0
- package/src/build/blueprint/scan/prompts.ts +164 -0
- package/src/build/blueprint/scan/published.ts +131 -0
- package/src/build/blueprint/scan/resolve.ts +398 -0
- package/src/build/blueprint/scan/routes.ts +109 -0
- package/src/build/blueprint/scan/scripts.ts +119 -0
- package/src/build/blueprint/scan/tool-bundle-worker.ts +69 -0
- package/src/build/blueprint/scan/tools.ts +610 -0
- package/src/build/blueprint/types.ts +28 -0
- package/src/build/extensions/config.ts +261 -0
- package/src/build/extensions/edit.ts +684 -0
- package/src/build/extensions/extensions.ts +731 -0
- package/src/build/extensions/index.ts +10 -0
- package/src/build/extensions/load.ts +350 -0
- package/src/build/extensions/registrations.ts +189 -0
- package/src/build/extensions/store.ts +200 -0
- package/src/build/frame/frame.ts +145 -0
- package/src/build/frame/index.ts +5 -0
- package/src/build/frame/migrate.ts +246 -0
- package/src/build/project/bundle/agent.ts +382 -0
- package/src/build/project/bundle/artifacts.ts +88 -0
- package/src/build/project/bundle/assets.ts +385 -0
- package/src/build/project/bundle/bundle.ts +160 -0
- package/src/build/project/bundle/imports.ts +102 -0
- package/src/build/project/bundle/index.ts +16 -0
- package/src/build/project/bundle/module.ts +130 -0
- package/src/build/project/bundle/source.ts +136 -0
- package/src/build/project/bundle/stage.ts +97 -0
- package/src/build/project/bundle/types.ts +111 -0
- package/src/build/project/cognet.ts +156 -0
- package/src/build/project/create/agent.ts +52 -0
- package/src/build/project/create/bench.ts +81 -0
- package/src/build/project/create/cognet.ts +102 -0
- package/src/build/project/create/extension.ts +63 -0
- package/src/build/project/create/module.ts +43 -0
- package/src/build/project/create/profile.ts +102 -0
- package/src/build/project/create/prompt.ts +68 -0
- package/src/build/project/create/templates.ts +88 -0
- package/src/build/project/deploy.ts +96 -0
- package/src/build/project/index.ts +40 -0
- package/src/build/project/installer.ts +616 -0
- package/src/build/project/kinds.ts +374 -0
- package/src/build/project/links.ts +33 -0
- package/src/build/project/manifest/bunfig.ts +139 -0
- package/src/build/project/manifest/config.ts +246 -0
- package/src/build/project/manifest/env.ts +184 -0
- package/src/build/project/manifest/index.ts +9 -0
- package/src/build/project/manifest/manifest.ts +49 -0
- package/src/build/project/manifest/model.ts +124 -0
- package/src/build/project/manifest/package.ts +386 -0
- package/src/build/project/manifest/text.ts +19 -0
- package/src/build/project/models/fetch.ts +123 -0
- package/src/build/project/models/index.ts +8 -0
- package/src/build/project/models/models.ts +111 -0
- package/src/build/project/models/specifier.ts +106 -0
- package/src/build/project/models/store.ts +202 -0
- package/src/build/project/modules/hash.ts +31 -0
- package/src/build/project/modules/index.ts +5 -0
- package/src/build/project/modules/lock.ts +78 -0
- package/src/build/project/modules/modules.ts +155 -0
- package/src/build/project/prepare.ts +709 -0
- package/src/build/project/project.ts +253 -0
- package/src/build/project/projects.ts +164 -0
- package/src/build/project/propagation.ts +120 -0
- package/src/build/project/publish/verify.ts +312 -0
- package/src/build/project/publish.ts +155 -0
- package/src/build/project/reconcile.ts +93 -0
- package/src/build/project/specifier.ts +42 -0
- package/src/build/project/tree.ts +615 -0
- package/src/build/project/treecache.ts +356 -0
- package/src/build/project/typegen/axon-dts.ts +362 -0
- package/src/build/project/typegen/cognet-dts.ts +91 -0
- package/src/build/project/typegen/components.ts +45 -0
- package/src/build/project/typegen/env.ts +59 -0
- package/src/build/project/typegen/generators.ts +108 -0
- package/src/build/project/typegen/hooks.ts +71 -0
- package/src/build/project/typegen/index.ts +137 -0
- package/src/build/project/typegen/prompt-dts.ts +40 -0
- package/src/build/project/typegen/prompts.ts +36 -0
- package/src/build/project/typegen/registry-dts.ts +109 -0
- package/src/build/project/typegen/scripts.ts +37 -0
- package/src/build/project/typegen/tools.ts +31 -0
- package/src/build/project/typegen/tsconfig.ts +243 -0
- package/src/build/project/typegen/tui-dts.ts +120 -0
- package/src/build/project/typegen/write.ts +40 -0
- package/src/build/project/verify.ts +268 -0
- package/src/build/project/watcher.ts +266 -0
- package/src/build/runtime/agent.ts +550 -0
- package/src/build/runtime/escalations.ts +159 -0
- package/src/build/runtime/index.ts +15 -0
- package/src/build/runtime/instances.ts +604 -0
- package/src/build/runtime/profile.ts +91 -0
- package/src/build/runtime/progress.ts +143 -0
- package/src/build/runtime/requests.ts +167 -0
- package/src/build/runtime/resolve.ts +159 -0
- package/src/build/runtime/runtime.ts +233 -0
- package/src/build/runtime/sessions/index.ts +5 -0
- package/src/build/runtime/sessions/record.ts +145 -0
- package/src/build/runtime/sessions/sessions.ts +240 -0
- package/src/build/runtime/zeno.ts +120 -0
- package/src/index.ts +11 -0
- package/src/link/agent-main.ts +395 -0
- package/src/link/index.ts +70 -0
- package/src/link/services.ts +120 -0
- package/src/platform.ts +293 -0
- package/src/procs/index.ts +15 -0
- package/src/procs/tree.ts +177 -0
- package/src/services/cloud.ts +419 -0
- package/src/services/control/client.ts +126 -0
- package/src/services/control/dispatch.ts +156 -0
- package/src/services/control/index.ts +17 -0
- package/src/services/control/protocol.ts +179 -0
- package/src/services/control/server.ts +241 -0
- package/src/services/deployments.ts +81 -0
- package/src/services/files.ts +329 -0
- package/src/services/index.ts +5 -0
- package/src/services/mic/capture.ts +248 -0
- package/src/services/mic/config.ts +109 -0
- package/src/services/mic/fft.ts +93 -0
- package/src/services/mic/index.ts +139 -0
- package/src/services/mic/visualizer.ts +46 -0
- package/src/services/ollama/catalog.ts +122 -0
- package/src/services/ollama/http.ts +124 -0
- package/src/services/ollama/index.ts +13 -0
- package/src/services/ollama/models.ts +153 -0
- package/src/services/ollama/ollama.ts +89 -0
- package/src/services/ollama/registry.ts +112 -0
- package/src/services/ollama/types.ts +72 -0
- package/src/services/prompts.ts +76 -0
- package/src/services/registry.ts +220 -0
- package/src/services/resources/hardware.ts +125 -0
- package/src/services/resources/index.ts +6 -0
- package/src/services/resources/reservations.ts +162 -0
- package/src/services/resources/resources.ts +156 -0
- package/src/services/running/index.ts +1 -0
- package/src/services/running/running.ts +200 -0
- package/src/services/store/disk.ts +97 -0
- package/src/services/store/index.ts +15 -0
- package/src/services/store/store.ts +729 -0
- package/src/services/store/types.ts +303 -0
- package/src/services/test/child.ts +150 -0
- package/src/services/test/events.ts +102 -0
- package/src/services/test/files.ts +26 -0
- package/src/services/test/frames.ts +39 -0
- package/src/services/test/index.ts +7 -0
- package/src/services/test/runner.ts +122 -0
- package/src/services/test/types.ts +26 -0
- package/src/services/update/contract.ts +77 -0
- package/src/services/update/index.ts +12 -0
- package/src/services/update/installer.ts +139 -0
- package/src/services/update/updates.ts +137 -0
- package/src/utils/fs.ts +148 -0
- package/src/utils/tsast.ts +102 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @arcforge/platform
|
|
2
|
+
|
|
3
|
+
The headless developer platform for [Axon](https://axon.arclabs.it).
|
|
4
|
+
|
|
5
|
+
Everything the CLI, the TUI and the Fleet extension do to projects and agents on this
|
|
6
|
+
machine — project discovery, blueprint scanning, typegen, agent lifecycle, registry,
|
|
7
|
+
benches and tests — with no terminal, no reactivity and no prompts of its own.
|
|
8
|
+
|
|
9
|
+
`Platform()` is the composition root: one object holding every tool a runtime needs.
|
|
10
|
+
Consumers get it and descend into it; they never construct its internals. That is what
|
|
11
|
+
lets one implementation serve a terminal, an editor extension and a CI run without any
|
|
12
|
+
of them knowing about the others.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @arcforge/platform
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Most people never install this directly. It arrives as a dependency of the Axon
|
|
19
|
+
framework when you scaffold an agent with `axon init`.
|
|
20
|
+
|
|
21
|
+
## Documentation
|
|
22
|
+
|
|
23
|
+
Full documentation is at **[axon.arclabs.it/docs/v2](https://axon.arclabs.it/docs/v2)**.
|
|
24
|
+
|
|
25
|
+
- [What is Axon?](https://axon.arclabs.it/docs/v2)
|
|
26
|
+
- [The CLI](https://axon.arclabs.it/docs/v2/cli)
|
|
27
|
+
- [The agent folder](https://axon.arclabs.it/docs/v2/agent/folder)
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
Proprietary. © ArcLabs
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arcforge/platform",
|
|
3
|
+
"version": "2.0.166",
|
|
4
|
+
"description": "The Axon developer platform — headless project discovery, blueprint scanning, typegen, agent lifecycle, registry, benches and tests. Shared by the CLI/TUI and the Fleet extension.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./*": "./src/*.ts",
|
|
11
|
+
"./bin/supervisor": "./src/bin/supervisor.ts",
|
|
12
|
+
"./bin/test-api": "./src/bin/test-api.ts",
|
|
13
|
+
"./bin/test-preload": "./src/bin/test-preload.ts",
|
|
14
|
+
"./bin/update-helper": "./src/bin/update-helper.ts",
|
|
15
|
+
"./build/bench": "./src/build/bench/index.ts",
|
|
16
|
+
"./build/blueprint": "./src/build/blueprint/index.ts",
|
|
17
|
+
"./build/blueprint/scan/declare": "./src/build/blueprint/scan/declare.ts",
|
|
18
|
+
"./build/cognet": "./src/build/blueprint/cognet/index.ts",
|
|
19
|
+
"./build/extensions": "./src/build/extensions/index.ts",
|
|
20
|
+
"./build/project": "./src/build/project/index.ts",
|
|
21
|
+
"./build/runtime": "./src/build/runtime/index.ts",
|
|
22
|
+
"./link": {
|
|
23
|
+
"types": "./src/link/index.ts",
|
|
24
|
+
"default": "./src/link/index.ts"
|
|
25
|
+
},
|
|
26
|
+
"./platform": "./src/platform.ts",
|
|
27
|
+
"./services": "./src/services/index.ts",
|
|
28
|
+
"./services/control": "./src/services/control/index.ts",
|
|
29
|
+
"./services/mic": "./src/services/mic/index.ts",
|
|
30
|
+
"./services/ollama": "./src/services/ollama/index.ts",
|
|
31
|
+
"./services/running": "./src/services/running/index.ts",
|
|
32
|
+
"./store": "./src/services/store/index.ts",
|
|
33
|
+
"./test": "./src/services/test/index.ts",
|
|
34
|
+
"./update": "./src/services/update/index.ts"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "bun test --parallel=4",
|
|
41
|
+
"test:serial": "bun test",
|
|
42
|
+
"test:watch": "bun test --watch",
|
|
43
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
44
|
+
"deploy": "echo \"This package is published ONLY by apps/tui/scripts/release.ts, which pins workspace:* deps to concrete versions first. Publishing it directly ships an unresolvable dependency.\" && exit 1"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@arcforge/session": "2.0.166",
|
|
48
|
+
"@arcforge/engines": "2.0.166",
|
|
49
|
+
"@arcforge/err": "2.0.166",
|
|
50
|
+
"@arcforge/types": "2.0.166",
|
|
51
|
+
"@arcforge/cloud": "2.0.166",
|
|
52
|
+
"@arcforge/capsule": "2.0.166",
|
|
53
|
+
"@arcforge/core": "2.0.166",
|
|
54
|
+
"@arcforge/vstr": "2.0.166",
|
|
55
|
+
"fft.js": "^4.0.4",
|
|
56
|
+
"h3": "^1.15.11",
|
|
57
|
+
"semver": "^7.7.4",
|
|
58
|
+
"sharp": "^0.35.3",
|
|
59
|
+
"typescript": "5.9.2",
|
|
60
|
+
"@arcforge/link": "2.0.166"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@arcforge/air": "2.0.165",
|
|
64
|
+
"@arcforge/cognet": "2.0.165",
|
|
65
|
+
"@arclabs/repo": "1.0.0",
|
|
66
|
+
"@types/bun": "latest",
|
|
67
|
+
"@types/semver": "^7.7.1"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { readFile, rm } from "node:fs/promises"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { tmpdir } from "node:os"
|
|
5
|
+
import {
|
|
6
|
+
UPDATE_REQUEST_ENV,
|
|
7
|
+
UPDATE_REQUEST_EXIT_CODE,
|
|
8
|
+
toArgv,
|
|
9
|
+
type UpdateRequest,
|
|
10
|
+
} from "../services/update/contract"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What axon's processes call themselves in ps/top/htop.
|
|
14
|
+
*
|
|
15
|
+
* One constant because the names have to stay related: the app is
|
|
16
|
+
* `APP_PROCESS_NAME`, the updater is that plus a suffix, and someone scanning a
|
|
17
|
+
* process list should see them as obviously the same product.
|
|
18
|
+
*/
|
|
19
|
+
const APP_PROCESS_NAME = "axon"
|
|
20
|
+
|
|
21
|
+
type SuperviseOpts = {
|
|
22
|
+
argv?: string[]
|
|
23
|
+
execPath?: string
|
|
24
|
+
root?: string
|
|
25
|
+
requestPath?: string
|
|
26
|
+
spawn?: typeof Bun.spawn
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* supervisor — the real CLI entrypoint.
|
|
31
|
+
*
|
|
32
|
+
* Bundled to index.js (the app itself becomes app.js — see vterm.config.ts), so
|
|
33
|
+
* every `axon` invocation is really this process spawning the app as a child.
|
|
34
|
+
* It exists for exactly one reason: an update cannot replace the binary of a
|
|
35
|
+
* running program, so something has to outlive the app and run the installer
|
|
36
|
+
* after it exits.
|
|
37
|
+
*
|
|
38
|
+
* The app signals that by exiting with UPDATE_REQUEST_EXIT_CODE after writing a
|
|
39
|
+
* request to the path in UPDATE_REQUEST_ENV. Any other exit code is passed
|
|
40
|
+
* straight through — this is transparent in the normal case.
|
|
41
|
+
*/
|
|
42
|
+
export async function supervise(opts: SuperviseOpts = {}): Promise<number> {
|
|
43
|
+
const argv = opts.argv ?? process.argv.slice(2)
|
|
44
|
+
const execPath = opts.execPath ?? process.execPath
|
|
45
|
+
const root = opts.root ?? import.meta.dir
|
|
46
|
+
const requestPath = opts.requestPath ?? join(tmpdir(), `axon-update-${process.pid}.json`)
|
|
47
|
+
const spawn = opts.spawn ?? Bun.spawn
|
|
48
|
+
|
|
49
|
+
// The app shares our foreground process group and owns interactive signal
|
|
50
|
+
// handling. Keep the supervisor alive until that child has actually exited.
|
|
51
|
+
const holdSignal = () => {}
|
|
52
|
+
process.on("SIGINT", holdSignal)
|
|
53
|
+
process.on("SIGTERM", holdSignal)
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// ── Why argv0 and not process.title ─────────────────────────────────
|
|
57
|
+
//
|
|
58
|
+
// Every axon process showed up as `bun` in ps/top/htop, which is
|
|
59
|
+
// useless the moment a machine runs more than one Bun program — "which
|
|
60
|
+
// bun is eating my CPU" could only be answered by matching on the
|
|
61
|
+
// script path.
|
|
62
|
+
//
|
|
63
|
+
// `process.title = "axon"` is the obvious fix and does NOT work here:
|
|
64
|
+
// Bun accepts the assignment and reads it back, but never propagates it
|
|
65
|
+
// to the OS, so neither `comm` nor the args column changes. Verified
|
|
66
|
+
// directly rather than assumed.
|
|
67
|
+
//
|
|
68
|
+
// argv0 does work. The kernel shows argv[0] as the command line, so the
|
|
69
|
+
// child renders as `axon app.js …` instead of `bun app.js …`. The
|
|
70
|
+
// executable is still `execPath` — only the name it reports changes.
|
|
71
|
+
const app = spawn({
|
|
72
|
+
cmd: [execPath, join(root, "app.js"), ...argv],
|
|
73
|
+
argv0: APP_PROCESS_NAME,
|
|
74
|
+
stdin: "inherit",
|
|
75
|
+
stdout: "inherit",
|
|
76
|
+
stderr: "inherit",
|
|
77
|
+
env: { ...process.env, [UPDATE_REQUEST_ENV]: requestPath },
|
|
78
|
+
})
|
|
79
|
+
const appCode = await app.exited
|
|
80
|
+
if (appCode !== UPDATE_REQUEST_EXIT_CODE) return appCode
|
|
81
|
+
|
|
82
|
+
const request = JSON.parse(await readFile(requestPath, "utf-8")) as UpdateRequest
|
|
83
|
+
// Named distinctly from the app: an update running after the TUI has
|
|
84
|
+
// exited is a different thing doing different work, and two rows called
|
|
85
|
+
// `axon` would not say which one is still alive.
|
|
86
|
+
const updater = spawn({
|
|
87
|
+
cmd: [execPath, join(root, "update-helper.js"), ...toArgv(request)],
|
|
88
|
+
argv0: `${APP_PROCESS_NAME}-update`,
|
|
89
|
+
stdin: "ignore",
|
|
90
|
+
stdout: "inherit",
|
|
91
|
+
stderr: "inherit",
|
|
92
|
+
env: process.env,
|
|
93
|
+
})
|
|
94
|
+
return await updater.exited
|
|
95
|
+
} finally {
|
|
96
|
+
process.off("SIGINT", holdSignal)
|
|
97
|
+
process.off("SIGTERM", holdSignal)
|
|
98
|
+
await rm(requestPath, { force: true }).catch(() => {})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (import.meta.main) process.exit(await supervise())
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as bun from "bun:test"
|
|
2
|
+
import { err } from "@arcforge/err"
|
|
3
|
+
export * from "bun:test"
|
|
4
|
+
|
|
5
|
+
type InstrumentedApi = Pick<typeof bun,
|
|
6
|
+
"describe" | "test" | "it" | "beforeAll" | "beforeEach" | "afterEach" | "afterAll"
|
|
7
|
+
>
|
|
8
|
+
|
|
9
|
+
const api = (globalThis as typeof globalThis & { __axon_test_api__?: InstrumentedApi }).__axon_test_api__
|
|
10
|
+
if (!api) throw err("TEST_PRELOAD_MISSING")
|
|
11
|
+
|
|
12
|
+
export const describe = api.describe
|
|
13
|
+
export const test = api.test
|
|
14
|
+
export const it = api.it
|
|
15
|
+
export const beforeAll = api.beforeAll
|
|
16
|
+
export const beforeEach = api.beforeEach
|
|
17
|
+
export const afterEach = api.afterEach
|
|
18
|
+
export const afterAll = api.afterAll
|
|
19
|
+
export const xdescribe = api.describe.skip
|
|
20
|
+
export const xtest = api.test.skip
|
|
21
|
+
export const xit = api.it.skip
|
|
22
|
+
|
|
23
|
+
// Assertions, mocks, timers, and every non-lifecycle API remain Bun-native.
|
|
24
|
+
export const expect = bun.expect
|
|
25
|
+
export const mock = bun.mock
|
|
26
|
+
export const spyOn = bun.spyOn
|
|
27
|
+
export const jest = bun.jest
|
|
28
|
+
export const setSystemTime = bun.setSystemTime
|
|
29
|
+
export const setDefaultTimeout = bun.setDefaultTimeout
|
|
30
|
+
export const onTestFinished = bun.onTestFinished
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks"
|
|
2
|
+
import { resolve } from "node:path"
|
|
3
|
+
import { pathToFileURL } from "node:url"
|
|
4
|
+
import {
|
|
5
|
+
afterAll as bunAfterAll,
|
|
6
|
+
afterEach as bunAfterEach,
|
|
7
|
+
beforeAll as bunBeforeAll,
|
|
8
|
+
beforeEach as bunBeforeEach,
|
|
9
|
+
describe as bunDescribe,
|
|
10
|
+
it as bunIt,
|
|
11
|
+
test as bunTest,
|
|
12
|
+
} from "bun:test"
|
|
13
|
+
import type { AxonError } from "@arcforge/err"
|
|
14
|
+
import { err } from "@arcforge/err"
|
|
15
|
+
import type { AxonTestEventFrame, AxonTestHookKind } from "@arcforge/types"
|
|
16
|
+
|
|
17
|
+
type Context = { suiteId?: string; testId?: string; hookId?: string; attempt?: number; resources?: Record<string, unknown> }
|
|
18
|
+
type CaseOutcome = { status: "passed" } | { status: "failed"; error: unknown }
|
|
19
|
+
type BeforeCase = (context: Context) => void | Promise<void>
|
|
20
|
+
type AfterCase = (context: Context, outcome: CaseOutcome) => void | Promise<void>
|
|
21
|
+
type Mode = "run" | "only" | "skip" | "todo" | "failing"
|
|
22
|
+
|
|
23
|
+
const file = process.env.AXON_TEST_FILE ?? "unknown"
|
|
24
|
+
const context = new AsyncLocalStorage<Context>()
|
|
25
|
+
const suiteStack: Array<{ id: string; name: string }> = []
|
|
26
|
+
const occurrences = new Map<string, number>()
|
|
27
|
+
const beforeCase = new Set<BeforeCase>()
|
|
28
|
+
const afterCase = new Set<AfterCase>()
|
|
29
|
+
|
|
30
|
+
function send(frame: AxonTestEventFrame): void {
|
|
31
|
+
const ipc = process as typeof process & { send?: (message: unknown) => void }
|
|
32
|
+
ipc.send?.({ channel: "axon:test", frame })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An Error's own fields are non-enumerable, so JSON.stringify() of one is
|
|
37
|
+
* `{}` — and this crosses to the runner as JSON. Every failing test therefore
|
|
38
|
+
* reported an empty error, which is worse than no error at all: it says
|
|
39
|
+
* something went wrong and refuses to say what. Copy the parts that matter
|
|
40
|
+
* onto a plain object so the message survives the boundary.
|
|
41
|
+
*/
|
|
42
|
+
function errorOf(value: unknown): AxonError {
|
|
43
|
+
const error = err(value)
|
|
44
|
+
|
|
45
|
+
// An Error's own fields are non-enumerable, so JSON.stringify() of one is
|
|
46
|
+
// `{}` — and this crosses to the runner as JSON. Every failing test
|
|
47
|
+
// therefore reported an empty error, which is worse than none: it says
|
|
48
|
+
// something went wrong and refuses to say what.
|
|
49
|
+
//
|
|
50
|
+
// Redefined as enumerable ON the error rather than spread into a new
|
|
51
|
+
// object: isAxonError() checks `value instanceof Error`, so a plain copy
|
|
52
|
+
// stops being an AxonError to everything downstream.
|
|
53
|
+
for (const key of ["message", "stack"] as const) {
|
|
54
|
+
const current = error[key]
|
|
55
|
+
if (current === undefined) continue
|
|
56
|
+
Object.defineProperty(error, key, { value: current, enumerable: true, writable: true, configurable: true })
|
|
57
|
+
}
|
|
58
|
+
return error
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function id(kind: "suite" | "test", name: string): string {
|
|
62
|
+
const base = [file, ...suiteStack.map(suite => suite.name), name].join("::")
|
|
63
|
+
const key = `${kind}:${base}`
|
|
64
|
+
const occurrence = occurrences.get(key) ?? 0
|
|
65
|
+
occurrences.set(key, occurrence + 1)
|
|
66
|
+
return `${key}:${occurrence}`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function frameContext(extra: Partial<Context> = {}): Omit<Context & { file: string }, "testRunId"> {
|
|
70
|
+
return { file, ...context.getStore(), ...extra }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function serialize(values: unknown[]): string[] {
|
|
74
|
+
return values.map(value => {
|
|
75
|
+
if (typeof value === "string") return value
|
|
76
|
+
try {
|
|
77
|
+
return JSON.stringify(value)
|
|
78
|
+
} catch {
|
|
79
|
+
return String(value)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function installConsole(): void {
|
|
85
|
+
for (const level of ["log", "info", "warn", "error", "debug"] as const) {
|
|
86
|
+
const original = console[level].bind(console)
|
|
87
|
+
console[level] = ((...values: unknown[]) => {
|
|
88
|
+
send({ type: "test:console", context: frameContext(), data: { level, values: serialize(values) } })
|
|
89
|
+
original(...values)
|
|
90
|
+
}) as typeof console[typeof level]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function runCallback(fn: (...args: any[]) => unknown, args: unknown[], doneStyle = fn.length > 0): Promise<unknown> {
|
|
95
|
+
if (!doneStyle) return Promise.resolve(fn(...args))
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
let settled = false
|
|
98
|
+
const done = (error?: unknown) => {
|
|
99
|
+
if (settled) return
|
|
100
|
+
settled = true
|
|
101
|
+
error === undefined ? resolve(undefined) : reject(error)
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const result = fn(...args, done)
|
|
105
|
+
if (result && typeof (result as PromiseLike<unknown>).then === "function") {
|
|
106
|
+
Promise.resolve(result).then(resolve, reject)
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
reject(error)
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function wrapDescribe(base: typeof bunDescribe, mode: Exclude<Mode, "failing"> = "run"): typeof bunDescribe {
|
|
115
|
+
function register(target: typeof bunDescribe, targetMode: Exclude<Mode, "failing">, name: string, fn: (...args: any[]) => void): void {
|
|
116
|
+
const suiteId = id("suite", String(name))
|
|
117
|
+
const parentSuiteId = suiteStack.at(-1)?.id
|
|
118
|
+
send({ type: "test:suite:declare", context: frameContext({ suiteId }), data: { name: String(name), ...(parentSuiteId ? { parentSuiteId } : {}), mode: targetMode } })
|
|
119
|
+
|
|
120
|
+
if (targetMode === "skip" || targetMode === "todo") return target(name, fn)
|
|
121
|
+
|
|
122
|
+
return target(name, (...args: any[]) => {
|
|
123
|
+
suiteStack.push({ id: suiteId, name: String(name) })
|
|
124
|
+
const started = { value: 0 }
|
|
125
|
+
bunBeforeAll(() => {
|
|
126
|
+
started.value = performance.now()
|
|
127
|
+
send({ type: "test:suite:start", context: frameContext({ suiteId }), data: { name: String(name) } })
|
|
128
|
+
})
|
|
129
|
+
fn(...args)
|
|
130
|
+
bunAfterAll(() => {
|
|
131
|
+
send({ type: "test:suite:complete", context: frameContext({ suiteId }), data: { name: String(name), durationMs: performance.now() - started.value } })
|
|
132
|
+
})
|
|
133
|
+
suiteStack.pop()
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const wrapped: any = (name: string, fn: () => void) => register(base, mode, name, fn)
|
|
138
|
+
wrapped.only = (name: string, fn: () => void) => register(base.only, "only", name, fn)
|
|
139
|
+
wrapped.skip = (name: string, fn: () => void) => register(base.skip, "skip", name, fn)
|
|
140
|
+
wrapped.todo = (name: string, fn: () => void) => register(base.todo, "todo", name, fn)
|
|
141
|
+
wrapped.concurrent = (name: string, fn: () => void) => register(base.concurrent, mode, name, fn)
|
|
142
|
+
wrapped.serial = (name: string, fn: () => void) => register(base.serial, mode, name, fn)
|
|
143
|
+
wrapped.if = (condition: boolean) => wrapDescribe(base.if(condition), condition ? mode : "skip")
|
|
144
|
+
wrapped.skipIf = (condition: boolean) => wrapDescribe(base.skipIf(condition), condition ? "skip" : mode)
|
|
145
|
+
wrapped.todoIf = (condition: boolean) => wrapDescribe(base.todoIf(condition), condition ? "todo" : mode)
|
|
146
|
+
wrapped.each = (table: unknown[]) => {
|
|
147
|
+
const target = base.each(table as never)
|
|
148
|
+
return (name: string, fn: () => void) => register(target as typeof bunDescribe, mode, name, fn)
|
|
149
|
+
}
|
|
150
|
+
return wrapped as typeof bunDescribe
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function wrapTest(base: typeof bunTest, mode: Mode = "run"): typeof bunTest {
|
|
154
|
+
function register(target: typeof bunTest, targetMode: Mode, name: string, fn: (...args: any[]) => unknown, options?: unknown, fromEach = false): void {
|
|
155
|
+
const testId = id("test", String(name))
|
|
156
|
+
const suite = suiteStack.map(item => item.name)
|
|
157
|
+
const suiteId = suiteStack.at(-1)?.id
|
|
158
|
+
let attempt = 0
|
|
159
|
+
send({ type: "test:case:declare", context: frameContext({ testId, suiteId }), data: { name: String(name), suite, mode: targetMode } })
|
|
160
|
+
|
|
161
|
+
// bun:test's callback type is narrower than the variadic shape this
|
|
162
|
+
// wrapper accepts (it also passes a `done` callback). The runtime
|
|
163
|
+
// contract is identical — same reason `options` is cast below.
|
|
164
|
+
if (targetMode === "skip") {
|
|
165
|
+
send({ type: "test:case:skip", context: frameContext({ testId, suiteId }), data: {} })
|
|
166
|
+
return target(name, fn as never, options as never)
|
|
167
|
+
}
|
|
168
|
+
if (targetMode === "todo") {
|
|
169
|
+
send({ type: "test:case:todo", context: frameContext({ testId, suiteId }), data: {} })
|
|
170
|
+
return target(name, fn as never, options as never)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return target(name, async (...args: unknown[]) => {
|
|
174
|
+
const currentAttempt = attempt++
|
|
175
|
+
const started = performance.now()
|
|
176
|
+
send({ type: "test:case:start", context: frameContext({ testId, suiteId, attempt: currentAttempt }), data: { name: String(name), suite } })
|
|
177
|
+
try {
|
|
178
|
+
const active: Context = { testId, suiteId, attempt: currentAttempt, resources: {} }
|
|
179
|
+
await context.run(active, async () => {
|
|
180
|
+
let outcome: CaseOutcome = { status: "passed" }
|
|
181
|
+
let failure: unknown
|
|
182
|
+
try {
|
|
183
|
+
for (const handler of beforeCase) await handler(active)
|
|
184
|
+
await runCallback(fn, args, !fromEach && fn.length > 0)
|
|
185
|
+
} catch (error) {
|
|
186
|
+
failure = error
|
|
187
|
+
outcome = { status: "failed", error }
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
for (const handler of afterCase) await handler(active, outcome)
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (failure !== undefined) throw new AggregateError([failure, error], "test and after-case lifecycle both failed")
|
|
193
|
+
throw error
|
|
194
|
+
}
|
|
195
|
+
if (failure !== undefined) throw failure
|
|
196
|
+
})
|
|
197
|
+
if (targetMode === "failing") {
|
|
198
|
+
send({ type: "test:case:fail", context: frameContext({ testId, suiteId, attempt: currentAttempt }), data: { durationMs: performance.now() - started, error: errorOf(new Error("Expected failing test to throw")) } })
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
send({ type: "test:case:pass", context: frameContext({ testId, suiteId, attempt: currentAttempt }), data: { durationMs: performance.now() - started } })
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (targetMode === "failing") {
|
|
204
|
+
send({ type: "test:case:pass", context: frameContext({ testId, suiteId, attempt: currentAttempt }), data: { durationMs: performance.now() - started } })
|
|
205
|
+
throw error
|
|
206
|
+
}
|
|
207
|
+
send({ type: "test:case:fail", context: frameContext({ testId, suiteId, attempt: currentAttempt }), data: { durationMs: performance.now() - started, error: errorOf(error) } })
|
|
208
|
+
throw error
|
|
209
|
+
}
|
|
210
|
+
}, options as never)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const wrapped: any = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base, mode, name, fn, options)
|
|
214
|
+
wrapped.only = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base.only, "only", name, fn, options)
|
|
215
|
+
wrapped.skip = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base.skip, "skip", name, fn, options)
|
|
216
|
+
wrapped.todo = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base.todo, "todo", name, fn, options)
|
|
217
|
+
wrapped.failing = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base.failing, "failing", name, fn, options)
|
|
218
|
+
wrapped.concurrent = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base.concurrent, mode, name, fn, options)
|
|
219
|
+
wrapped.serial = (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(base.serial, mode, name, fn, options)
|
|
220
|
+
wrapped.if = (condition: boolean) => wrapTest(base.if(condition), condition ? mode : "skip")
|
|
221
|
+
wrapped.skipIf = (condition: boolean) => wrapTest(base.skipIf(condition), condition ? "skip" : mode)
|
|
222
|
+
wrapped.todoIf = (condition: boolean) => wrapTest(base.todoIf(condition), condition ? "todo" : mode)
|
|
223
|
+
wrapped.failingIf = (condition: boolean) => wrapTest(base.failingIf(condition), condition ? "failing" : mode)
|
|
224
|
+
wrapped.concurrentIf = (condition: boolean) => wrapTest(base.concurrentIf(condition), mode)
|
|
225
|
+
wrapped.serialIf = (condition: boolean) => wrapTest(base.serialIf(condition), mode)
|
|
226
|
+
wrapped.each = (table: unknown[]) => {
|
|
227
|
+
const target = base.each(table as never)
|
|
228
|
+
return (name: string, fn: (...args: any[]) => unknown, options?: unknown) => register(target as typeof bunTest, mode, name, fn, options, true)
|
|
229
|
+
}
|
|
230
|
+
return wrapped as typeof bunTest
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function wrapHook(base: typeof bunBeforeAll, kind: AxonTestHookKind): typeof bunBeforeAll {
|
|
234
|
+
return ((fn: (...args: any[]) => unknown, options?: unknown) => {
|
|
235
|
+
const suiteId = suiteStack.at(-1)?.id
|
|
236
|
+
const hookId = id("test", `$hook:${kind}`)
|
|
237
|
+
return base(async (...args: unknown[]) => {
|
|
238
|
+
const started = performance.now()
|
|
239
|
+
send({ type: "test:hook:start", context: frameContext({ hookId, suiteId }), data: { kind } })
|
|
240
|
+
try {
|
|
241
|
+
await context.run({ hookId, suiteId }, () => runCallback(fn, args))
|
|
242
|
+
send({ type: "test:hook:complete", context: frameContext({ hookId, suiteId }), data: { kind, durationMs: performance.now() - started } })
|
|
243
|
+
} catch (error) {
|
|
244
|
+
send({ type: "test:hook:fail", context: frameContext({ hookId, suiteId }), data: { kind, durationMs: performance.now() - started, error: errorOf(error) } })
|
|
245
|
+
throw error
|
|
246
|
+
}
|
|
247
|
+
}, options as never)
|
|
248
|
+
}) as typeof bunBeforeAll
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
installConsole()
|
|
252
|
+
// Monitor without installing uncaughtException/unhandledRejection handlers,
|
|
253
|
+
// which would change Bun's native crash semantics by marking them handled.
|
|
254
|
+
process.on("uncaughtExceptionMonitor", error => send({ type: "test:process:fault", context: frameContext(), data: { kind: "uncaught", error: errorOf(error) } }))
|
|
255
|
+
|
|
256
|
+
const test = wrapTest(bunTest)
|
|
257
|
+
const instrumented = {
|
|
258
|
+
describe: wrapDescribe(bunDescribe),
|
|
259
|
+
test,
|
|
260
|
+
it: wrapTest(bunIt),
|
|
261
|
+
beforeAll: wrapHook(bunBeforeAll, "beforeAll"),
|
|
262
|
+
beforeEach: wrapHook(bunBeforeEach, "beforeEach"),
|
|
263
|
+
afterEach: wrapHook(bunAfterEach, "afterEach"),
|
|
264
|
+
afterAll: wrapHook(bunAfterAll, "afterAll"),
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
;(globalThis as any).__axon_test_api__ = instrumented
|
|
268
|
+
;(globalThis as any).__axon_test_context__ = {
|
|
269
|
+
current: () => context.getStore(),
|
|
270
|
+
beforeCase(handler: BeforeCase) {
|
|
271
|
+
beforeCase.add(handler)
|
|
272
|
+
return () => beforeCase.delete(handler)
|
|
273
|
+
},
|
|
274
|
+
afterCase(handler: AfterCase) {
|
|
275
|
+
afterCase.add(handler)
|
|
276
|
+
return () => afterCase.delete(handler)
|
|
277
|
+
},
|
|
278
|
+
}
|
|
279
|
+
Object.assign(globalThis, instrumented)
|
|
280
|
+
|
|
281
|
+
// Bun's built-in test globals are lexical in current releases; assigning
|
|
282
|
+
// globalThis alone does not replace them. Transform only the explicitly
|
|
283
|
+
// selected test file in memory — user source is never rewritten on disk.
|
|
284
|
+
const target = resolve(process.cwd(), file)
|
|
285
|
+
const apiUrl = pathToFileURL(new URL("./test-api.ts", import.meta.url).pathname).href
|
|
286
|
+
const injected = `import { describe, test, it, xdescribe, xtest, xit, beforeAll, beforeEach, afterEach, afterAll } from ${JSON.stringify(apiUrl)};\n`
|
|
287
|
+
const targetFilter = new RegExp(`^${target.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`)
|
|
288
|
+
|
|
289
|
+
Bun.plugin({
|
|
290
|
+
name: "axon-test-events",
|
|
291
|
+
setup(builder) {
|
|
292
|
+
builder.onLoad({ filter: targetFilter }, async args => {
|
|
293
|
+
let source = await Bun.file(args.path).text()
|
|
294
|
+
const bindingImport = /import\s+(?!["'])[^;]+?from\s+["']bun:test["']/s.test(source)
|
|
295
|
+
source = source.replace(/(["'])bun:test\1/g, JSON.stringify(apiUrl))
|
|
296
|
+
if (!bindingImport) source = injected + source
|
|
297
|
+
const extension = args.path.split(".").pop()
|
|
298
|
+
const loader = extension === "tsx" ? "tsx" : extension === "jsx" ? "jsx" : extension === "js" || extension === "mjs" || extension === "cjs" ? "js" : "ts"
|
|
299
|
+
return { contents: source, loader }
|
|
300
|
+
})
|
|
301
|
+
},
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
// Domain extensions load after test context/instrumentation is installed, but
|
|
305
|
+
// before Bun imports the selected test file. Bun only honors one --preload
|
|
306
|
+
// reliably, so TestRunner composes extensions here rather than stacking flags.
|
|
307
|
+
const extensionPreloads = JSON.parse(process.env.AXON_TEST_EXTENSION_PRELOADS ?? "[]") as string[]
|
|
308
|
+
for (const extension of extensionPreloads) await import(pathToFileURL(extension).href)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { err, isAxonError } from "@arcforge/err"
|
|
3
|
+
import { fromArgv } from "../services/update/contract"
|
|
4
|
+
import { Installer, type InstallerIo } from "../services/update/installer"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* update-helper — the process that replaces the installed Axon.
|
|
8
|
+
*
|
|
9
|
+
* Spawned by the supervisor AFTER the app has exited, because a package manager
|
|
10
|
+
* cannot replace the binary of a running program. Bundled to update-helper.js
|
|
11
|
+
* by the TUI's build (see vterm.config.ts) and never imported by the app.
|
|
12
|
+
*
|
|
13
|
+
* Deliberately thin: everything it does lives in Installer(), which is
|
|
14
|
+
* ordinary library code with injectable IO. This file is the executable
|
|
15
|
+
* boundary — argv in, exit code out.
|
|
16
|
+
*/
|
|
17
|
+
export async function main(argv: string[], io: InstallerIo & {
|
|
18
|
+
exit?: (code: number) => void
|
|
19
|
+
} = {}): Promise<void> {
|
|
20
|
+
const exit = io.exit ?? (code => process.exit(code))
|
|
21
|
+
const report = io.err ?? (message => process.stderr.write(message))
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
exit(await Installer(io).apply(fromArgv(argv)))
|
|
25
|
+
} catch (cause) {
|
|
26
|
+
const failure = isAxonError(cause) ? cause : err(cause)
|
|
27
|
+
report(`Axon updater failed: ${failure.message}\n`)
|
|
28
|
+
exit(1)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (import.meta.main) await main(process.argv.slice(2))
|