@1aboveio/engineering-skills 0.0.0-stage → 0.1.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/README.md +28 -2
- package/package.json +34 -4
- package/skills/better-review/LICENSE +3 -0
- package/skills/better-review/SKILL.md +249 -0
- package/skills/better-review/agents/openai.yaml +9 -0
- package/skills/better-review/references/domain-hazards.md +53 -0
- package/skills/better-review/references/passes.md +147 -0
- package/skills/better-review/references/result.md +151 -0
- package/skills/better-review/release-check.mjs +93 -0
- package/skills/better-review/scripts/pr-context.mjs +212 -0
- package/skills/better-review/scripts/pr-context.test.mjs +168 -0
- package/skills/better-review/scripts/rereview-scope.mjs +503 -0
- package/skills/better-review/scripts/rereview-scope.test.mjs +587 -0
- package/skills/better-review/scripts/scan-diff.mjs +365 -0
- package/skills/better-review/scripts/scan-diff.test.mjs +414 -0
- package/skills/better-review/scripts/vendor-sync.test.mjs +96 -0
- package/skills/e2e-test/LICENSE +3 -0
- package/skills/e2e-test/SKILL.md +98 -0
- package/skills/e2e-test/assets/ci-gates.cloudbuild.yaml +24 -0
- package/skills/e2e-test/references/authoring/auth-flows.md +159 -0
- package/skills/e2e-test/references/authoring/playwright-config.md +73 -0
- package/skills/e2e-test/references/authoring/playwright-patterns.md +144 -0
- package/skills/e2e-test/references/ci-integration.md +25 -0
- package/skills/e2e-test/references/ci-playwright-container.md +290 -0
- package/skills/e2e-test/references/presentation-sweep.md +104 -0
- package/skills/e2e-test/references/reviewing.md +41 -0
- package/skills/e2e-test/references/route-manifest.md +51 -0
- package/skills/e2e-test/release-check.mjs +93 -0
- package/skills/e2e-test/scripts/detect-routes-nextjs.mjs +200 -0
- package/skills/e2e-test/scripts/presentation-checks.mjs +171 -0
- package/skills/e2e-test/scripts/presentation-checks.test.mjs +106 -0
- package/skills/e2e-test/scripts/presentation-perceivability.mjs +179 -0
- package/skills/e2e-test/scripts/presentation-perceivability.test.mjs +117 -0
- package/skills/e2e-test/scripts/presentation-reachability.mjs +154 -0
- package/skills/e2e-test/scripts/presentation-reachability.test.mjs +69 -0
- package/skills/e2e-test/scripts/presentation-render-health.mjs +141 -0
- package/skills/e2e-test/scripts/presentation-render-health.test.mjs +98 -0
- package/skills/e2e-test/scripts/presentation-sweep.mjs +147 -0
- package/skills/e2e-test/scripts/presentation-sweep.test.mjs +71 -0
- package/skills/e2e-test/scripts/presentation-temporal.mjs +127 -0
- package/skills/e2e-test/scripts/presentation-temporal.test.mjs +59 -0
- package/skills/e2e-test/scripts/project-route-manifest.mjs +82 -0
- package/skills/e2e-test/scripts/project-route-manifest.test.mjs +76 -0
- package/skills/e2e-test/scripts/validate-manifest.mjs +106 -0
- package/skills/engineering-runtime/LICENSE +3 -0
- package/skills/engineering-runtime/SKILL.md +11 -0
- package/skills/engineering-runtime/agents/openai.yaml +6 -0
- package/skills/engineering-runtime/coherence/workflow.json +597 -0
- package/skills/engineering-runtime/engineering-runtime.test.mjs +68 -0
- package/skills/engineering-runtime/release-check.mjs +93 -0
- package/skills/engineering-runtime/scripts/exact-head-artifact.mjs +131 -0
- package/skills/engineering-runtime/scripts/head-check-set.mjs +398 -0
- package/skills/engineering-runtime/scripts/invocation-policy.mjs +187 -0
- package/skills/engineering-runtime/scripts/invocation-policy.test.mjs +95 -0
- package/skills/engineering-runtime/scripts/main-module.mjs +79 -0
- package/skills/engineering-runtime/scripts/main-module.test.mjs +288 -0
- package/skills/engineering-runtime/scripts/mergify-yaml.mjs +11 -0
- package/skills/engineering-runtime/scripts/package-lock.json +43 -0
- package/skills/engineering-runtime/scripts/package.json +10 -0
- package/skills/engineering-runtime/scripts/required-check-plan.mjs +223 -0
- package/skills/engineering-runtime/scripts/required-check-plan.test.mjs +96 -0
- package/skills/engineering-runtime/scripts/review-completion.mjs +56 -0
- package/skills/engineering-runtime/scripts/workflow-coherence.mjs +595 -0
- package/skills/engineering-runtime/scripts/workflow-policy.mjs +189 -0
- package/skills/engineering-runtime/scripts/yaml-mapping.mjs +18 -0
- package/skills/ensure-coverage/LICENSE +3 -0
- package/skills/ensure-coverage/SKILL.md +129 -0
- package/skills/ensure-coverage/references/breadth/coverage-ledger.md +92 -0
- package/skills/ensure-coverage/references/breadth/inventory-contract.md +85 -0
- package/skills/ensure-coverage/references/breadth/surface-baseline.md +44 -0
- package/skills/ensure-coverage/references/breadth/surface-discovery.md +16 -0
- package/skills/ensure-coverage/references/depth/characterization.md +68 -0
- package/skills/ensure-coverage/references/depth/coverage.config.example.json +19 -0
- package/skills/ensure-coverage/references/depth/grading.md +35 -0
- package/skills/ensure-coverage/references/depth/mock-policy.md +57 -0
- package/skills/ensure-coverage/references/depth/test-smells.md +39 -0
- package/skills/ensure-coverage/references/enforcement/ci-contract.md +44 -0
- package/skills/ensure-coverage/references/examples/coverage-ledger.md +110 -0
- package/skills/ensure-coverage/references/examples/refund-flow.md +35 -0
- package/skills/ensure-coverage/references/presentation/axis.md +64 -0
- package/skills/ensure-coverage/references/process/audit-mode.md +27 -0
- package/skills/ensure-coverage/references/process/output-template.md +139 -0
- package/skills/ensure-coverage/references/process/test-strategy.md +56 -0
- package/skills/ensure-coverage/release-check.mjs +93 -0
- package/skills/ensure-coverage/schemas/coverage-config.schema.json +67 -0
- package/skills/ensure-coverage/schemas/coverage-file.schema.json +140 -0
- package/skills/ensure-coverage/scripts/README.md +99 -0
- package/skills/ensure-coverage/scripts/adapters/nextjs-inventory.mjs +182 -0
- package/skills/ensure-coverage/scripts/adapters/nextjs-inventory.test.mjs +96 -0
- package/skills/ensure-coverage/scripts/check-quarantine-expiry.mjs +105 -0
- package/skills/ensure-coverage/scripts/check-quarantine-expiry.test.mjs +47 -0
- package/skills/ensure-coverage/scripts/ci-audit.mjs +137 -0
- package/skills/ensure-coverage/scripts/ci-audit.test.mjs +86 -0
- package/skills/ensure-coverage/scripts/coverage-ledger.mjs +674 -0
- package/skills/ensure-coverage/scripts/coverage-ledger.test.mjs +447 -0
- package/skills/ensure-coverage/scripts/design-parity.mjs +591 -0
- package/skills/ensure-coverage/scripts/design-parity.test.mjs +552 -0
- package/skills/ensure-coverage/scripts/lint-tests.mjs +282 -0
- package/skills/ensure-coverage/scripts/lint-tests.test.mjs +289 -0
- package/skills/ensure-coverage/scripts/mock-policy-config.mjs +176 -0
- package/skills/ensure-coverage/scripts/mock-policy-config.test.mjs +119 -0
- package/skills/ensure-coverage/scripts/package.json +19 -0
- package/skills/golden-path/LICENSE +3 -0
- package/skills/golden-path/SKILL.md +230 -0
- package/skills/golden-path/agents/openai.yaml +3 -0
- package/skills/golden-path/assets/golden-paths.example.json +57 -0
- package/skills/golden-path/references/contract.md +239 -0
- package/skills/golden-path/references/migration.md +111 -0
- package/skills/golden-path/release-check.mjs +93 -0
- package/skills/golden-path/scripts/golden-path-core.mjs +1779 -0
- package/skills/golden-path/scripts/golden-path.mjs +6 -0
- package/skills/golden-path/scripts/golden-path.test.mjs +1457 -0
- package/skills/harness-runtime/LICENSE +3 -0
- package/skills/harness-runtime/SKILL.md +19 -0
- package/skills/harness-runtime/agents/openai.yaml +6 -0
- package/skills/harness-runtime/bin/discover-models.mjs +4 -0
- package/skills/harness-runtime/bin/model-catalog.mjs +4 -0
- package/skills/harness-runtime/contracts.md +15 -0
- package/skills/harness-runtime/discover-models.mjs +392 -0
- package/skills/harness-runtime/discover-models.test.mjs +363 -0
- package/skills/harness-runtime/fixtures/native-question-schemas.json +33 -0
- package/skills/harness-runtime/fixtures/question-responses.json +54 -0
- package/skills/harness-runtime/harness-runtime.test.mjs +967 -0
- package/skills/harness-runtime/index.mjs +767 -0
- package/skills/harness-runtime/model-catalog-seed.test.mjs +829 -0
- package/skills/harness-runtime/model-catalog.mjs +787 -0
- package/skills/harness-runtime/model-catalog.test.mjs +366 -0
- package/skills/harness-runtime/native-question-contracts.md +37 -0
- package/skills/harness-runtime/references/model-catalog-seed.json +408 -0
- package/skills/harness-runtime/references/model-catalog.md +57 -0
- package/skills/harness-runtime/release-check.mjs +93 -0
- package/skills/resolve-issues/LICENSE +3 -0
- package/skills/resolve-issues/SKILL.md +250 -0
- package/skills/resolve-issues/agents/openai.yaml +9 -0
- package/skills/resolve-issues/plugin-hooks.json +17 -0
- package/skills/resolve-issues/references/canary.md +28 -0
- package/skills/resolve-issues/references/ci.md +105 -0
- package/skills/resolve-issues/references/done.md +25 -0
- package/skills/resolve-issues/references/dropbox.md +90 -0
- package/skills/resolve-issues/references/expire.md +318 -0
- package/skills/resolve-issues/references/exploration.md +202 -0
- package/skills/resolve-issues/references/implementation.md +303 -0
- package/skills/resolve-issues/references/preflight.md +445 -0
- package/skills/resolve-issues/references/review.md +228 -0
- package/skills/resolve-issues/references/shared-modules.md +44 -0
- package/skills/resolve-issues/references/task-plan.md +264 -0
- package/skills/resolve-issues/release-check.mjs +93 -0
- package/skills/resolve-issues/scripts/cleanup-runs.mjs +364 -0
- package/skills/resolve-issues/scripts/cleanup-runs.test.mjs +280 -0
- package/skills/resolve-issues/scripts/discover-models.mjs +9 -0
- package/skills/resolve-issues/scripts/dropbox.mjs +473 -0
- package/skills/resolve-issues/scripts/dropbox.test.mjs +346 -0
- package/skills/resolve-issues/scripts/findings-reuse.mjs +98 -0
- package/skills/resolve-issues/scripts/findings-reuse.test.mjs +88 -0
- package/skills/resolve-issues/scripts/github-reviews.mjs +384 -0
- package/skills/resolve-issues/scripts/github-reviews.test.mjs +264 -0
- package/skills/resolve-issues/scripts/install-hooks.mjs +135 -0
- package/skills/resolve-issues/scripts/install-hooks.test.mjs +79 -0
- package/skills/resolve-issues/scripts/issue-tree.mjs +162 -0
- package/skills/resolve-issues/scripts/issue-tree.test.mjs +107 -0
- package/skills/resolve-issues/scripts/manual-invocation.test.mjs +14 -0
- package/skills/resolve-issues/scripts/model-catalog.mjs +9 -0
- package/skills/resolve-issues/scripts/next-actions-capacity.test.mjs +149 -0
- package/skills/resolve-issues/scripts/next-actions.mjs +856 -0
- package/skills/resolve-issues/scripts/next-actions.test.mjs +915 -0
- package/skills/resolve-issues/scripts/plan-sync.mjs +269 -0
- package/skills/resolve-issues/scripts/plan-sync.test.mjs +156 -0
- package/skills/resolve-issues/scripts/preflight-models.mjs +736 -0
- package/skills/resolve-issues/scripts/preflight-models.test.mjs +448 -0
- package/skills/resolve-issues/scripts/ready-check.mjs +185 -0
- package/skills/resolve-issues/scripts/ready-check.test.mjs +217 -0
- package/skills/resolve-issues/scripts/rehydrate.mjs +98 -0
- package/skills/resolve-issues/scripts/rehydrate.test.mjs +91 -0
- package/skills/resolve-issues/scripts/review-verdict.mjs +509 -0
- package/skills/resolve-issues/scripts/review-verdict.test.mjs +1060 -0
- package/skills/resolve-issues/scripts/size-check.mjs +492 -0
- package/skills/resolve-issues/scripts/size-check.test.mjs +458 -0
- package/skills/resolve-release/LICENSE +3 -0
- package/skills/resolve-release/SKILL.md +215 -0
- package/skills/resolve-release/agents/openai.yaml +8 -0
- package/skills/resolve-release/flows/cloud-run-canary.md +13 -0
- package/skills/resolve-release/flows/cloud-run.md +7 -0
- package/skills/resolve-release/flows/root-tag-npm.md +13 -0
- package/skills/resolve-release/flows/workspace-npm.md +22 -0
- package/skills/resolve-release/references/canary.md +51 -0
- package/skills/resolve-release/references/candidate.md +41 -0
- package/skills/resolve-release/references/cut.md +131 -0
- package/skills/resolve-release/references/dark-launch.md +66 -0
- package/skills/resolve-release/references/flows.md +150 -0
- package/skills/resolve-release/references/preflight.md +154 -0
- package/skills/resolve-release/references/prepared-metadata.md +260 -0
- package/skills/resolve-release/references/promotion.md +82 -0
- package/skills/resolve-release/references/publish.md +232 -0
- package/skills/resolve-release/references/workspace-npm.md +103 -0
- package/skills/resolve-release/release-check.mjs +93 -0
- package/skills/resolve-release/scripts/apply.mjs +212 -0
- package/skills/resolve-release/scripts/apply.test.mjs +99 -0
- package/skills/resolve-release/scripts/dark-flags.mjs +134 -0
- package/skills/resolve-release/scripts/dark-flags.test.mjs +100 -0
- package/skills/resolve-release/scripts/flow.mjs +500 -0
- package/skills/resolve-release/scripts/flow.test.mjs +340 -0
- package/skills/resolve-release/scripts/green-head.mjs +231 -0
- package/skills/resolve-release/scripts/green-head.test.mjs +101 -0
- package/skills/resolve-release/scripts/npm-version-absence.mjs +138 -0
- package/skills/resolve-release/scripts/npm-version-absence.test.mjs +426 -0
- package/skills/resolve-release/scripts/plan-npm.test.mjs +659 -0
- package/skills/resolve-release/scripts/plan-toml-boundary.test.mjs +317 -0
- package/skills/resolve-release/scripts/plan-uv.test.mjs +291 -0
- package/skills/resolve-release/scripts/plan.mjs +806 -0
- package/skills/resolve-release/scripts/plan.test.mjs +428 -0
- package/skills/rush-issues/LICENSE +3 -0
- package/skills/rush-issues/SKILL.md +58 -0
- package/skills/rush-issues/agents/openai.yaml +8 -0
- package/skills/rush-issues/rehydrate.mjs +10 -0
- package/skills/rush-issues/release-check.mjs +93 -0
- package/skills/rush-release/LICENSE +3 -0
- package/skills/rush-release/SKILL.md +35 -0
- package/skills/rush-release/agents/openai.yaml +8 -0
- package/skills/rush-release/release-check.mjs +93 -0
- package/skills/test-quality/LICENSE +3 -0
- package/skills/test-quality/SKILL.md +79 -0
- package/skills/test-quality/references/audit.md +80 -0
- package/skills/test-quality/references/lint.md +24 -0
- package/skills/test-quality/references/principles.md +143 -0
- package/skills/test-quality/references/testing-conventions.md +9 -0
- package/skills/test-quality/release-check.mjs +93 -0
- package/skills/test-quality/scripts/lint-tests.mjs +574 -0
- package/skills/test-quality/scripts/lint-tests.test.mjs +591 -0
- package/skills/test-quality/scripts/mock-policy-config.mjs +176 -0
- package/skills/test-quality/scripts/mock-policy-config.test.mjs +119 -0
- package/skills/test-quality/scripts/persist-conventions-core.mjs +117 -0
- package/skills/test-quality/scripts/persist-conventions.mjs +17 -0
- package/skills/test-quality/scripts/persist-conventions.test.mjs +104 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Install, or check, the compaction hook that runs rehydrate.mjs: after a context compaction the
|
|
3
|
+
// coordinator is told to read its skills in full again.
|
|
4
|
+
//
|
|
5
|
+
// install-hooks.mjs [--check] [--harness claude|codex] [--home <dir>] [--json] [--exit-missing]
|
|
6
|
+
//
|
|
7
|
+
// Writes one SessionStart entry with matcher `compact` to ~/.claude/settings.json (Claude Code)
|
|
8
|
+
// and ~/.codex/hooks.json (Codex), for each harness whose home directory exists. Idempotent: an
|
|
9
|
+
// entry already running rehydrate.mjs is kept, and its path updated when the skill moved. Every
|
|
10
|
+
// other setting and hook is left as it was. Pi gets the same re-read from its workflow
|
|
11
|
+
// extension, not from a hook file.
|
|
12
|
+
//
|
|
13
|
+
// --check writes nothing. Claude Code counts as installed when the engineering-workflow plugin
|
|
14
|
+
// is enabled, since the plugin ships the same hook; then no settings hook is written either,
|
|
15
|
+
// or the message would arrive twice.
|
|
16
|
+
//
|
|
17
|
+
// Exit 0 whenever it ran: each harness's status (absent, plugin, installed, updated, or
|
|
18
|
+
// missing) is in the output, and --check ends with a `missing: ...` line when one lacks the hook
|
|
19
|
+
// (--json prints `{ results, missing }`). Exit 2 on bad input or a settings file that is not JSON
|
|
20
|
+
// (never overwritten). --exit-missing restores the old exit 1 when --check finds one missing
|
|
21
|
+
// (deprecated).
|
|
22
|
+
|
|
23
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
24
|
+
import { homedir } from 'node:os'
|
|
25
|
+
import { dirname, join } from 'node:path'
|
|
26
|
+
import { fileURLToPath } from 'node:url'
|
|
27
|
+
|
|
28
|
+
import { isMainModule } from '../../engineering-runtime/scripts/main-module.mjs'
|
|
29
|
+
|
|
30
|
+
export const REHYDRATE = join(dirname(fileURLToPath(import.meta.url)), 'rehydrate.mjs')
|
|
31
|
+
export const PLUGIN = 'engineering-workflow@'
|
|
32
|
+
const HARNESSES = {
|
|
33
|
+
claude: { dir: '.claude', file: 'settings.json' },
|
|
34
|
+
codex: { dir: '.codex', file: 'hooks.json' },
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class InstallHooksError extends Error {}
|
|
38
|
+
|
|
39
|
+
export const hookCommand = (script = REHYDRATE) => `node "${script}" --hook`
|
|
40
|
+
const isOurs = (h) => typeof h?.command === 'string' && h.command.includes('rehydrate.mjs')
|
|
41
|
+
|
|
42
|
+
// The settings object with the hook in place, and whether anything changed.
|
|
43
|
+
export function withHook(settings, command = hookCommand()) {
|
|
44
|
+
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
45
|
+
if (!isObject(settings ?? {})) throw new InstallHooksError('the settings file is not a JSON object; fix it by hand, nothing was written')
|
|
46
|
+
const next = structuredClone(settings ?? {})
|
|
47
|
+
next.hooks ??= {}
|
|
48
|
+
next.hooks.SessionStart ??= []
|
|
49
|
+
if (!isObject(next.hooks) || !Array.isArray(next.hooks.SessionStart)) {
|
|
50
|
+
throw new InstallHooksError('hooks.SessionStart is not a list; fix it by hand, nothing was written')
|
|
51
|
+
}
|
|
52
|
+
let found = false
|
|
53
|
+
let changed = false
|
|
54
|
+
for (const group of next.hooks.SessionStart) {
|
|
55
|
+
for (const h of group?.hooks ?? []) {
|
|
56
|
+
if (!isOurs(h)) continue
|
|
57
|
+
found = true
|
|
58
|
+
if (h.command !== command) { h.command = command; changed = true }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!found) {
|
|
62
|
+
next.hooks.SessionStart.push({ matcher: 'compact', hooks: [{ type: 'command', command, timeout: 10 }] })
|
|
63
|
+
changed = true
|
|
64
|
+
}
|
|
65
|
+
return { settings: next, changed }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const pluginEnabled = (settings, harness) => harness === 'claude'
|
|
69
|
+
&& Object.entries(settings?.enabledPlugins ?? {}).some(([k, v]) => k.startsWith(PLUGIN) && v === true)
|
|
70
|
+
|
|
71
|
+
export function hasHook(settings, harness) {
|
|
72
|
+
const groups = Array.isArray(settings?.hooks?.SessionStart) ? settings.hooks.SessionStart : []
|
|
73
|
+
return groups.some((g) => (g?.hooks ?? []).some(isOurs)) || pluginEnabled(settings, harness)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function readJson(file) {
|
|
77
|
+
if (!existsSync(file)) return {}
|
|
78
|
+
try { return JSON.parse(readFileSync(file, 'utf8')) } catch (error) {
|
|
79
|
+
throw new InstallHooksError(`${file} is not JSON (${error.message}); fix it by hand, nothing was written`)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// [{ harness, file, status }] with status installed | updated | plugin | missing | absent (no
|
|
84
|
+
// harness home).
|
|
85
|
+
export function run({ home = homedir(), check = false, harness } = {}) {
|
|
86
|
+
const names = harness ? [harness] : Object.keys(HARNESSES)
|
|
87
|
+
const out = []
|
|
88
|
+
for (const name of names) {
|
|
89
|
+
const h = HARNESSES[name]
|
|
90
|
+
if (!h) throw new InstallHooksError(`unknown harness ${name}: use claude or codex`)
|
|
91
|
+
const file = join(home, h.dir, h.file)
|
|
92
|
+
if (!existsSync(join(home, h.dir))) { out.push({ harness: name, file, status: 'absent' }); continue }
|
|
93
|
+
const settings = readJson(file)
|
|
94
|
+
if (pluginEnabled(settings, name)) { out.push({ harness: name, file, status: 'plugin' }); continue }
|
|
95
|
+
if (check) { out.push({ harness: name, file, status: hasHook(settings, name) ? 'installed' : 'missing' }); continue }
|
|
96
|
+
const { settings: next, changed } = withHook(settings)
|
|
97
|
+
if (changed) {
|
|
98
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
99
|
+
writeFileSync(`${file}.tmp`, `${JSON.stringify(next, null, 2)}\n`)
|
|
100
|
+
renameSync(`${file}.tmp`, file)
|
|
101
|
+
}
|
|
102
|
+
out.push({ harness: name, file, status: changed ? 'updated' : 'installed' })
|
|
103
|
+
}
|
|
104
|
+
return out
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function parseCliArgs(argv) {
|
|
108
|
+
const opts = { check: false }
|
|
109
|
+
for (let i = 0; i < argv.length; i++) {
|
|
110
|
+
if (argv[i] === '--check') { opts.check = true; continue }
|
|
111
|
+
if (argv[i] === '--json') { opts.json = true; continue }
|
|
112
|
+
if (argv[i] === '--exit-missing') { opts.exitMissing = true; continue }
|
|
113
|
+
if (['--home', '--harness'].includes(argv[i]) && argv[i + 1] !== undefined) { opts[argv[i].slice(2)] = argv[++i]; continue }
|
|
114
|
+
throw new InstallHooksError('usage: install-hooks.mjs [--check] [--harness claude|codex] [--home <dir>] [--json] [--exit-missing]')
|
|
115
|
+
}
|
|
116
|
+
return opts
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (isMainModule(import.meta.url)) {
|
|
120
|
+
try {
|
|
121
|
+
const opts = parseCliArgs(process.argv.slice(2))
|
|
122
|
+
const results = run(opts)
|
|
123
|
+
const missing = results.filter((r) => r.status === 'missing').map((r) => r.harness)
|
|
124
|
+
if (opts.json) process.stdout.write(`${JSON.stringify({ results, missing }, null, 2)}\n`)
|
|
125
|
+
else {
|
|
126
|
+
for (const r of results) process.stdout.write(`${r.harness.padEnd(8)}${r.status.padEnd(11)}${r.file}\n`)
|
|
127
|
+
if (missing.length) process.stdout.write(`missing: ${missing.join(', ')} (run without --check to install)\n`)
|
|
128
|
+
if (results.some((r) => r.status === 'updated')) process.stdout.write('Codex may ask you to trust the new hook at its next start.\n')
|
|
129
|
+
}
|
|
130
|
+
process.exitCode = opts.exitMissing && missing.length ? 1 : 0
|
|
131
|
+
} catch (error) {
|
|
132
|
+
process.stderr.write(`install-hooks: ${error.message}\n`)
|
|
133
|
+
process.exitCode = 2
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { spawnSync } from 'node:child_process'
|
|
4
|
+
import fs from 'node:fs'
|
|
5
|
+
import os from 'node:os'
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
import { run, withHook, hookCommand, REHYDRATE } from './install-hooks.mjs'
|
|
10
|
+
|
|
11
|
+
const SCRIPT = path.join(path.dirname(fileURLToPath(import.meta.url)), 'install-hooks.mjs')
|
|
12
|
+
|
|
13
|
+
function home(files = {}) {
|
|
14
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'install-hooks-'))
|
|
15
|
+
for (const [rel, body] of Object.entries(files)) {
|
|
16
|
+
fs.mkdirSync(path.dirname(path.join(dir, rel)), { recursive: true })
|
|
17
|
+
fs.writeFileSync(path.join(dir, rel), typeof body === 'string' ? body : JSON.stringify(body))
|
|
18
|
+
}
|
|
19
|
+
return dir
|
|
20
|
+
}
|
|
21
|
+
const read = (dir, rel) => JSON.parse(fs.readFileSync(path.join(dir, rel), 'utf8'))
|
|
22
|
+
|
|
23
|
+
test('installs into both harnesses, keeps every other setting and hook, and a second run changes nothing', () => {
|
|
24
|
+
const herdr = { hooks: [{ type: 'command', command: 'bash herdr.sh session' }] }
|
|
25
|
+
const dir = home({
|
|
26
|
+
'.claude/settings.json': { model: 'opus', hooks: { SessionStart: [herdr], Stop: [{ hooks: [] }] } },
|
|
27
|
+
'.codex/hooks.json': { hooks: { SessionStart: [herdr] } },
|
|
28
|
+
})
|
|
29
|
+
assert.deepEqual(run({ home: dir }).map((r) => `${r.harness}:${r.status}`), ['claude:updated', 'codex:updated'])
|
|
30
|
+
const claude = read(dir, '.claude/settings.json')
|
|
31
|
+
assert.equal(claude.model, 'opus')
|
|
32
|
+
assert.deepEqual(claude.hooks.Stop, [{ hooks: [] }])
|
|
33
|
+
assert.deepEqual(claude.hooks.SessionStart, [herdr, { matcher: 'compact', hooks: [{ type: 'command', command: hookCommand(), timeout: 10 }] }])
|
|
34
|
+
assert.deepEqual(read(dir, '.codex/hooks.json').hooks.SessionStart[1].matcher, 'compact')
|
|
35
|
+
assert.deepEqual(run({ home: dir }).map((r) => r.status), ['installed', 'installed'])
|
|
36
|
+
assert.deepEqual(run({ home: dir, check: true }).map((r) => r.status), ['installed', 'installed'])
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('a moved skill updates the old entry in place instead of adding a second', () => {
|
|
40
|
+
const old = { hooks: { SessionStart: [{ matcher: 'compact', hooks: [{ type: 'command', command: 'node "/old/resolve-issues/scripts/rehydrate.mjs" --hook' }] }] } }
|
|
41
|
+
const { settings, changed } = withHook(old)
|
|
42
|
+
assert.equal(changed, true)
|
|
43
|
+
assert.equal(settings.hooks.SessionStart.length, 1)
|
|
44
|
+
assert.equal(settings.hooks.SessionStart[0].hooks[0].command, `node "${REHYDRATE}" --hook`)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('check: a missing hook is reported in the output (exit 0; --exit-missing exits 1) and nothing is written; an enabled plugin counts; no harness home is absent', () => {
|
|
48
|
+
const dir = home({ '.claude/settings.json': { model: 'opus' } })
|
|
49
|
+
const out = spawnSync(process.execPath, [SCRIPT, '--check', '--home', dir], { encoding: 'utf8' })
|
|
50
|
+
assert.equal(out.status, 0, out.stderr)
|
|
51
|
+
assert.match(out.stdout, /claude {2}missing/)
|
|
52
|
+
assert.match(out.stdout, /codex {3}absent/)
|
|
53
|
+
assert.match(out.stdout, /^missing: claude/m)
|
|
54
|
+
const json = JSON.parse(spawnSync(process.execPath, [SCRIPT, '--check', '--json', '--home', dir], { encoding: 'utf8' }).stdout)
|
|
55
|
+
assert.deepEqual(json.missing, ['claude'])
|
|
56
|
+
assert.equal(spawnSync(process.execPath, [SCRIPT, '--check', '--exit-missing', '--home', dir], { encoding: 'utf8' }).status, 1)
|
|
57
|
+
assert.equal(spawnSync(process.execPath, [SCRIPT, '--bogus'], { encoding: 'utf8' }).status, 2)
|
|
58
|
+
assert.deepEqual(read(dir, '.claude/settings.json'), { model: 'opus' })
|
|
59
|
+
const plugin = home({ '.claude/settings.json': { enabledPlugins: { 'engineering-workflow@1aboveio-engineering-skills': true } } })
|
|
60
|
+
assert.deepEqual(run({ home: plugin, check: true, harness: 'claude' }).map((r) => r.status), ['plugin'])
|
|
61
|
+
assert.deepEqual(run({ home: plugin, harness: 'claude' }).map((r) => r.status), ['plugin'], 'the plugin ships the hook: no second copy')
|
|
62
|
+
assert.equal(read(plugin, '.claude/settings.json').hooks, undefined)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('a settings root or SessionStart of the wrong shape is refused, not silently kept', () => {
|
|
66
|
+
for (const body of [[], { hooks: { SessionStart: {} } }]) {
|
|
67
|
+
const dir = home({ '.claude/settings.json': body })
|
|
68
|
+
assert.throws(() => run({ home: dir, harness: 'claude' }), /fix it by hand/)
|
|
69
|
+
assert.deepEqual(read(dir, '.claude/settings.json'), body)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('a settings file that is not JSON is never overwritten', () => {
|
|
74
|
+
const dir = home({ '.claude/settings.json': '{ "model": "opus", // comment\n}' })
|
|
75
|
+
const out = spawnSync(process.execPath, [SCRIPT, '--home', dir, '--harness', 'claude'], { encoding: 'utf8' })
|
|
76
|
+
assert.equal(out.status, 2)
|
|
77
|
+
assert.match(out.stderr, /is not JSON/)
|
|
78
|
+
assert.equal(fs.readFileSync(path.join(dir, '.claude/settings.json'), 'utf8'), '{ "model": "opus", // comment\n}')
|
|
79
|
+
})
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Fetch a spec's GitHub issue tree (native sub-issues at any depth, each issue's labels and
|
|
3
|
+
// native `blockedBy` links) in as few calls as possible: one GraphQL query covers three
|
|
4
|
+
// levels, and follow-up queries run only where GitHub truncated something.
|
|
5
|
+
//
|
|
6
|
+
// issue-tree.mjs --issue <owner/name#123> [--json]
|
|
7
|
+
//
|
|
8
|
+
// Exit 0 whenever it ran (an incomplete tree is `complete: false` with `errors`, not a failure);
|
|
9
|
+
// 2 for a bad command.
|
|
10
|
+
//
|
|
11
|
+
// GraphQL caps a query at 500,000 potential nodes, counted from every `first:` multiplied
|
|
12
|
+
// down the nesting, so the levels narrow (50, 20, 10 sub-issues) and each issue asks for at
|
|
13
|
+
// most 20 labels and 10 blockers. A follow-up runs only for: an issue below the third
|
|
14
|
+
// level that has sub-issues (re-rooted query), an issue with more sub-issues than its
|
|
15
|
+
// level returned (pages of child numbers, each child re-rooted), and an issue with more
|
|
16
|
+
// labels or blockers than fit (one wide detail query). Transient failures (HTTP 502/503/
|
|
17
|
+
// 504, EOF, timeouts, connection resets) retry; anything still failing is listed in
|
|
18
|
+
// `errors` and the tree is marked incomplete, never guessed.
|
|
19
|
+
//
|
|
20
|
+
// Result: { root, complete, errors, nodes: { "owner/name#n": node } } where a node is
|
|
21
|
+
// { key, repo, number, title, state ('open'|'closed'), url, labels, blockedBy: [{ key, state }],
|
|
22
|
+
// children: [key] | null (null = not fetched), parent }.
|
|
23
|
+
|
|
24
|
+
import { execFileSync } from 'node:child_process'
|
|
25
|
+
|
|
26
|
+
import { isMainModule } from '../../engineering-runtime/scripts/main-module.mjs'
|
|
27
|
+
|
|
28
|
+
export const WIDTHS = [50, 20, 10]
|
|
29
|
+
const LABELS = 20
|
|
30
|
+
const BLOCKERS = 10
|
|
31
|
+
const WIDE = 100
|
|
32
|
+
const TRANSIENT = /\b(?:502|503|504)\b|EOF|ETIMEDOUT|timed? ?out|ECONNRESET|socket hang up|Bad Gateway|Service Unavailable|Gateway Timeout/i
|
|
33
|
+
|
|
34
|
+
const fields = (labels, blockers) => `number title state url repository { nameWithOwner }
|
|
35
|
+
labels(first: ${labels}) { totalCount nodes { name } }
|
|
36
|
+
blockedBy(first: ${blockers}) { totalCount nodes { number state repository { nameWithOwner } } }`
|
|
37
|
+
|
|
38
|
+
function level(depth) {
|
|
39
|
+
if (depth >= WIDTHS.length) return 'subIssuesSummary { total }'
|
|
40
|
+
return `subIssues(first: ${WIDTHS[depth]}) { totalCount pageInfo { hasNextPage endCursor }
|
|
41
|
+
nodes { ${fields(LABELS, BLOCKERS)} ${level(depth + 1)} } }`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const TREE_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
|
|
45
|
+
repository(owner: $owner, name: $name) { issue(number: $number) { ${fields(LABELS, BLOCKERS)} ${level(0)} } } }`
|
|
46
|
+
|
|
47
|
+
export const PAGE_QUERY = `query($owner: String!, $name: String!, $number: Int!, $after: String!) {
|
|
48
|
+
repository(owner: $owner, name: $name) { issue(number: $number) {
|
|
49
|
+
subIssues(first: ${WIDE}, after: $after) { pageInfo { hasNextPage endCursor } nodes { number repository { nameWithOwner } } } } } }`
|
|
50
|
+
|
|
51
|
+
export const DETAIL_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
|
|
52
|
+
repository(owner: $owner, name: $name) { issue(number: $number) { ${fields(WIDE, WIDE)} } } }`
|
|
53
|
+
|
|
54
|
+
export const keyOf = (repo, number) => `${repo}#${number}`
|
|
55
|
+
const split = (key) => { const i = key.lastIndexOf('#'); return { repo: key.slice(0, i), number: Number(key.slice(i + 1)) } }
|
|
56
|
+
|
|
57
|
+
// Retry a call while it fails transiently; `sleep` is injected so tests do not wait.
|
|
58
|
+
export function withRetry(fn, { attempts = 3, sleep = sleepSync } = {}) {
|
|
59
|
+
return (...args) => {
|
|
60
|
+
for (let i = 1; ; i++) {
|
|
61
|
+
try { return fn(...args) } catch (error) {
|
|
62
|
+
if (i >= attempts || !TRANSIENT.test(String(error?.message || error))) throw error
|
|
63
|
+
sleep(1000 * i)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function sleepSync(ms) { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms) }
|
|
70
|
+
|
|
71
|
+
// `graphql(query, variables)` returns the response's `data`; inject it to test without GitHub.
|
|
72
|
+
export function fetchTree(rootRef, { graphql = ghGraphql, attempts = 3, sleep } = {}) {
|
|
73
|
+
const call = withRetry(graphql, { attempts, sleep })
|
|
74
|
+
const nodes = {}
|
|
75
|
+
const errors = []
|
|
76
|
+
const root = keyOf(rootRef.repo, rootRef.number)
|
|
77
|
+
const issueOf = (key, query, extra = {}) => {
|
|
78
|
+
const { repo, number } = split(key)
|
|
79
|
+
const [owner, name] = repo.split('/')
|
|
80
|
+
const issue = call(query, { owner, name, number, ...extra })?.repository?.issue
|
|
81
|
+
if (!issue) throw new Error(`issue ${key} not found`)
|
|
82
|
+
return issue
|
|
83
|
+
}
|
|
84
|
+
const followUps = []
|
|
85
|
+
|
|
86
|
+
// Record an issue and everything nested under it; queue follow-ups for what was cut off.
|
|
87
|
+
const record = (raw, parent) => {
|
|
88
|
+
const repo = raw.repository?.nameWithOwner
|
|
89
|
+
const key = keyOf(repo, raw.number)
|
|
90
|
+
const prior = nodes[key]
|
|
91
|
+
const node = {
|
|
92
|
+
key, repo, number: raw.number, title: raw.title ?? null,
|
|
93
|
+
state: String(raw.state || '').toLowerCase(), url: raw.url ?? null,
|
|
94
|
+
labels: (raw.labels?.nodes ?? []).map((l) => l.name),
|
|
95
|
+
blockedBy: (raw.blockedBy?.nodes ?? []).map((b) => ({ key: keyOf(b.repository?.nameWithOwner ?? repo, b.number), state: String(b.state || '').toLowerCase() })),
|
|
96
|
+
children: null,
|
|
97
|
+
parent: prior?.parent ?? parent,
|
|
98
|
+
}
|
|
99
|
+
nodes[key] = node
|
|
100
|
+
if ((raw.labels?.totalCount ?? 0) > node.labels.length || (raw.blockedBy?.totalCount ?? 0) > node.blockedBy.length) followUps.push({ kind: 'detail', key })
|
|
101
|
+
if (raw.subIssues) {
|
|
102
|
+
node.children = raw.subIssues.nodes.map((child) => record(child, key))
|
|
103
|
+
if (raw.subIssues.pageInfo?.hasNextPage) followUps.push({ kind: 'page', key, after: raw.subIssues.pageInfo.endCursor })
|
|
104
|
+
} else if ((raw.subIssuesSummary?.total ?? 0) === 0) {
|
|
105
|
+
node.children = []
|
|
106
|
+
} else {
|
|
107
|
+
followUps.push({ kind: 'reroot', key })
|
|
108
|
+
}
|
|
109
|
+
return key
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
record(issueOf(root, TREE_QUERY), null)
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return { root, complete: false, errors: [{ key: root, error: String(error?.message || error) }], nodes }
|
|
116
|
+
}
|
|
117
|
+
while (followUps.length) {
|
|
118
|
+
const job = followUps.shift()
|
|
119
|
+
try {
|
|
120
|
+
if (job.kind === 'reroot') record(issueOf(job.key, TREE_QUERY), nodes[job.key]?.parent ?? null)
|
|
121
|
+
else if (job.kind === 'detail') {
|
|
122
|
+
const raw = issueOf(job.key, DETAIL_QUERY)
|
|
123
|
+
const node = nodes[job.key]
|
|
124
|
+
node.labels = (raw.labels?.nodes ?? []).map((l) => l.name)
|
|
125
|
+
node.blockedBy = (raw.blockedBy?.nodes ?? []).map((b) => ({ key: keyOf(b.repository?.nameWithOwner ?? node.repo, b.number), state: String(b.state || '').toLowerCase() }))
|
|
126
|
+
} else if (job.kind === 'page') {
|
|
127
|
+
const page = issueOf(job.key, PAGE_QUERY, { after: job.after }).subIssues
|
|
128
|
+
for (const child of page.nodes) {
|
|
129
|
+
const childKey = keyOf(child.repository?.nameWithOwner, child.number)
|
|
130
|
+
nodes[job.key].children.push(childKey)
|
|
131
|
+
nodes[childKey] = { key: childKey, parent: job.key }
|
|
132
|
+
followUps.push({ kind: 'reroot', key: childKey })
|
|
133
|
+
}
|
|
134
|
+
if (page.pageInfo?.hasNextPage) followUps.push({ kind: 'page', key: job.key, after: page.pageInfo.endCursor })
|
|
135
|
+
}
|
|
136
|
+
} catch (error) {
|
|
137
|
+
errors.push({ key: job.key, error: String(error?.message || error) })
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { root, complete: errors.length === 0, errors, nodes }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function ghGraphql(query, variables) {
|
|
144
|
+
const args = ['api', 'graphql', '-f', `query=${query}`]
|
|
145
|
+
for (const [name, value] of Object.entries(variables)) args.push(typeof value === 'number' ? '-F' : '-f', `${name}=${value}`)
|
|
146
|
+
const out = JSON.parse(execFileSync('gh', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 60_000 }))
|
|
147
|
+
if (out.errors?.length) throw new Error(out.errors.map((e) => e.message).join('; '))
|
|
148
|
+
return out.data
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (isMainModule(import.meta.url)) {
|
|
152
|
+
const i = process.argv.indexOf('--issue')
|
|
153
|
+
const m = /^([^/\s#]+\/[^/\s#]+)#(\d+)$/.exec(process.argv[i + 1] ?? '')
|
|
154
|
+
if (i < 0 || !m) {
|
|
155
|
+
console.error('usage: issue-tree.mjs --issue <owner/name#123>')
|
|
156
|
+
process.exitCode = 2
|
|
157
|
+
} else {
|
|
158
|
+
const tree = fetchTree({ repo: m[1], number: Number(m[2]) })
|
|
159
|
+
console.log(JSON.stringify(tree, null, 2))
|
|
160
|
+
// exit 0 whenever it ran: `complete` and `errors` in the output say whether the tree is whole
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { DETAIL_QUERY, PAGE_QUERY, TREE_QUERY, WIDTHS, fetchTree, withRetry } from './issue-tree.mjs'
|
|
5
|
+
|
|
6
|
+
// A fake GitHub GraphQL endpoint over issues keyed "o/r#n": { state, labels, blockedBy, children }.
|
|
7
|
+
// It honors the query's level widths, so truncation and follow-ups behave as on GitHub.
|
|
8
|
+
function fakeGraphql(issues, { fail = {} } = {}) {
|
|
9
|
+
const calls = []
|
|
10
|
+
const node = (key, depth, widths) => {
|
|
11
|
+
const i = issues[key]
|
|
12
|
+
const [repo, n] = key.split('#')
|
|
13
|
+
const labels = i.labels ?? []
|
|
14
|
+
const blockers = i.blockedBy ?? []
|
|
15
|
+
const out = {
|
|
16
|
+
number: Number(n), title: `t${n}`, state: (i.state ?? 'open').toUpperCase(), url: null, repository: { nameWithOwner: repo },
|
|
17
|
+
labels: { totalCount: labels.length, nodes: labels.slice(0, widths.labels).map((name) => ({ name })) },
|
|
18
|
+
blockedBy: { totalCount: blockers.length, nodes: blockers.slice(0, widths.blockers).map((b) => ({ number: Number(b.split('#')[1]), state: (issues[b]?.state ?? 'open').toUpperCase(), repository: { nameWithOwner: b.split('#')[0] } })) },
|
|
19
|
+
}
|
|
20
|
+
const kids = i.children ?? []
|
|
21
|
+
if (depth >= WIDTHS.length) out.subIssuesSummary = { total: kids.length }
|
|
22
|
+
else {
|
|
23
|
+
const shown = kids.slice(0, WIDTHS[depth])
|
|
24
|
+
out.subIssues = { totalCount: kids.length, pageInfo: { hasNextPage: kids.length > shown.length, endCursor: String(shown.length) }, nodes: shown.map((k) => node(k, depth + 1, widths)) }
|
|
25
|
+
}
|
|
26
|
+
return out
|
|
27
|
+
}
|
|
28
|
+
const graphql = (query, { owner, name, number, after }) => {
|
|
29
|
+
const key = `${owner}/${name}#${number}`
|
|
30
|
+
const kind = query === TREE_QUERY ? 'tree' : query === DETAIL_QUERY ? 'detail' : query === PAGE_QUERY ? 'page' : 'unknown'
|
|
31
|
+
calls.push(`${kind} ${key}`)
|
|
32
|
+
if (fail[key]) { const err = fail[key]; if (typeof err === 'number') { fail[key]--; throw new Error('HTTP 502 Bad Gateway') } throw new Error(err) }
|
|
33
|
+
if (!issues[key]) return { repository: { issue: null } }
|
|
34
|
+
if (kind === 'tree') return { repository: { issue: node(key, 0, { labels: 20, blockers: 10 }) } }
|
|
35
|
+
if (kind === 'detail') { const full = node(key, WIDTHS.length, { labels: 100, blockers: 100 }); delete full.subIssuesSummary; return { repository: { issue: full } } }
|
|
36
|
+
const kids = issues[key].children.slice(Number(after), Number(after) + 100)
|
|
37
|
+
return { repository: { issue: { subIssues: { pageInfo: { hasNextPage: Number(after) + 100 < issues[key].children.length, endCursor: String(Number(after) + 100) }, nodes: kids.map((k) => ({ number: Number(k.split('#')[1]), repository: { nameWithOwner: k.split('#')[0] } })) } } } }
|
|
38
|
+
}
|
|
39
|
+
return { graphql, calls }
|
|
40
|
+
}
|
|
41
|
+
const noSleep = () => {}
|
|
42
|
+
|
|
43
|
+
test('one query fetches three levels with labels and blockers', () => {
|
|
44
|
+
const { graphql, calls } = fakeGraphql({
|
|
45
|
+
'o/r#1': { children: ['o/r#2', 'o/r#3'] },
|
|
46
|
+
'o/r#2': { state: 'closed', labels: ['ready-for-agent'] },
|
|
47
|
+
'o/r#3': { children: ['x/y#4'], blockedBy: ['o/r#2'] },
|
|
48
|
+
'x/y#4': { labels: ['ready-for-agent'] },
|
|
49
|
+
})
|
|
50
|
+
const tree = fetchTree({ repo: 'o/r', number: 1 }, { graphql, sleep: noSleep })
|
|
51
|
+
assert.equal(tree.complete, true)
|
|
52
|
+
assert.deepEqual(calls, ['tree o/r#1'])
|
|
53
|
+
assert.deepEqual(tree.nodes['o/r#3'].children, ['x/y#4'])
|
|
54
|
+
assert.deepEqual(tree.nodes['o/r#3'].blockedBy, [{ key: 'o/r#2', state: 'closed' }])
|
|
55
|
+
assert.equal(tree.nodes['x/y#4'].parent, 'o/r#3')
|
|
56
|
+
assert.equal(tree.nodes['o/r#2'].state, 'closed')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('follow-ups run only where GitHub truncated: depth, child pages, wide labels or blockers', () => {
|
|
60
|
+
const many = Array.from({ length: 55 }, (_, i) => `o/r#${100 + i}`)
|
|
61
|
+
const issues = {
|
|
62
|
+
'o/r#1': { children: ['o/r#2', ...many] },
|
|
63
|
+
'o/r#2': { children: ['o/r#3'], blockedBy: Array.from({ length: 12 }, (_, i) => `o/r#${200 + i}`) },
|
|
64
|
+
'o/r#3': { children: ['o/r#4'] },
|
|
65
|
+
'o/r#4': { children: ['o/r#5'] },
|
|
66
|
+
'o/r#5': {},
|
|
67
|
+
}
|
|
68
|
+
for (const k of many) issues[k] = {}
|
|
69
|
+
const { graphql, calls } = fakeGraphql(issues)
|
|
70
|
+
const tree = fetchTree({ repo: 'o/r', number: 1 }, { graphql, sleep: noSleep })
|
|
71
|
+
assert.equal(tree.complete, true)
|
|
72
|
+
assert.equal(tree.nodes['o/r#1'].children.length, 56, 'every child, past the first level width')
|
|
73
|
+
assert.deepEqual(tree.nodes['o/r#4'].children, ['o/r#5'], 'the fourth level came from a re-rooted query')
|
|
74
|
+
assert.equal(tree.nodes['o/r#5'].parent, 'o/r#4')
|
|
75
|
+
assert.equal(tree.nodes['o/r#2'].blockedBy.length, 12, 'a wide detail query filled the blockers')
|
|
76
|
+
const pagedChildren = many.slice(49).map((k) => `tree ${k}`)
|
|
77
|
+
assert.deepEqual([...calls].sort(), ['tree o/r#1', 'detail o/r#2', 'tree o/r#4', 'page o/r#1', ...pagedChildren].sort(), 'one follow-up per truncation, nothing else')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('transient failures retry; a lasting failure marks the tree incomplete', () => {
|
|
81
|
+
const issues = { 'o/r#1': { children: ['o/r#2'] }, 'o/r#2': {} }
|
|
82
|
+
const flaky = fakeGraphql(issues, { fail: { 'o/r#1': 2 } })
|
|
83
|
+
assert.equal(fetchTree({ repo: 'o/r', number: 1 }, { graphql: flaky.graphql, sleep: noSleep }).complete, true)
|
|
84
|
+
assert.equal(flaky.calls.length, 3)
|
|
85
|
+
const down = fakeGraphql(issues, { fail: { 'o/r#1': 5 } })
|
|
86
|
+
const tree = fetchTree({ repo: 'o/r', number: 1 }, { graphql: down.graphql, sleep: noSleep })
|
|
87
|
+
assert.equal(tree.complete, false)
|
|
88
|
+
assert.match(tree.errors[0].error, /502/)
|
|
89
|
+
const denied = fakeGraphql(issues, { fail: { 'o/r#1': 'Could not resolve to a Repository' } })
|
|
90
|
+
fetchTree({ repo: 'o/r', number: 1 }, { graphql: denied.graphql, sleep: noSleep })
|
|
91
|
+
assert.equal(denied.calls.length, 1, 'a non-transient error is not retried')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('withRetry gives up after its attempts', () => {
|
|
95
|
+
let n = 0
|
|
96
|
+
const call = withRetry(() => { n++; throw new Error('read: EOF') }, { attempts: 3, sleep: noSleep })
|
|
97
|
+
assert.throws(call, /EOF/)
|
|
98
|
+
assert.equal(n, 3)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('the tree query stays under GitHub’s 500,000-node limit', () => {
|
|
102
|
+
// GitHub multiplies `first:` down the nesting; each issue also asks for 20 labels and 10 blockers.
|
|
103
|
+
let issues = 1
|
|
104
|
+
let total = 0
|
|
105
|
+
for (const width of WIDTHS) { issues *= width; total += issues * (1 + 20 + 10) }
|
|
106
|
+
assert.ok(total < 500_000, `estimated ${total} nodes`)
|
|
107
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { dirname, resolve } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
import { manualOnlyPolicyFindings } from '../../engineering-runtime/scripts/invocation-policy.mjs'
|
|
7
|
+
|
|
8
|
+
const engineeringRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
|
|
9
|
+
|
|
10
|
+
test('issue and release orchestrators require explicit invocation', () => {
|
|
11
|
+
for (const name of ['resolve-issues', 'rush-issues', 'rush-release', 'resolve-release']) {
|
|
12
|
+
assert.deepEqual(manualOnlyPolicyFindings(resolve(engineeringRoot, name)), [], name)
|
|
13
|
+
}
|
|
14
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Thin wrapper: canonical ownership lives in harness-runtime.
|
|
2
|
+
export * from '../../harness-runtime/model-catalog.mjs'
|
|
3
|
+
|
|
4
|
+
import { runCli } from '../../harness-runtime/model-catalog.mjs'
|
|
5
|
+
import { isMainModule } from '../../engineering-runtime/scripts/main-module.mjs'
|
|
6
|
+
|
|
7
|
+
if (isMainModule(import.meta.url)) {
|
|
8
|
+
process.exit(runCli(process.argv.slice(2)))
|
|
9
|
+
}
|