@1aboveio/engineering-skills 0.0.0-stage → 0.1.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 +28 -2
- package/package.json +33 -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 +116 -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,364 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Reclaim disk from finished resolve-issues runs without losing work or evidence.
|
|
3
|
+
//
|
|
4
|
+
// cleanup-runs.mjs [--repo <dir>] [--older-than-days <n>] [--log-days <n>] [--apply]
|
|
5
|
+
// cleanup-runs.mjs --merged <unit-workspace> [--apply]
|
|
6
|
+
//
|
|
7
|
+
// Sweep mode looks at every run under <repo>/.resolve-issues/rush/, aged by its
|
|
8
|
+
// task-plan.json (the file the orchestrator saves on every transition):
|
|
9
|
+
//
|
|
10
|
+
// idle under --older-than-days (default 3) untouched
|
|
11
|
+
// idle under --log-days (default 30) downloads go; records and logs stay
|
|
12
|
+
// idle longer records stay; logs go too
|
|
13
|
+
//
|
|
14
|
+
// Downloads are everything that can be fetched or rebuilt: tool caches, SDKs,
|
|
15
|
+
// browsers, emulator disks, installs, builds, and a clean clone's tracked source
|
|
16
|
+
// and .git. Logs are text evidence (.log, .txt, .json, .jsonl, .md, .out, .err,
|
|
17
|
+
// logcat) up to EVIDENCE_MAX_BYTES, wherever they sit, except inside a tool
|
|
18
|
+
// cache; inside a non-Git copy of a repository (a folder with a lockfile) only
|
|
19
|
+
// .log and logcat files, and text under test-results/, logs/, and similar. Records are the run's own small .json, .jsonl and .md files near the
|
|
20
|
+
// top of the run, outside any clone.
|
|
21
|
+
//
|
|
22
|
+
// A Git workspace never loses work. A clean one with nothing unpushed loses its
|
|
23
|
+
// tracked files, .git and downloads and keeps its logs. One with uncommitted
|
|
24
|
+
// changes, unpushed commits, or a stash keeps everything git tracks or would
|
|
25
|
+
// show as untracked; only its git-ignored paths are swept.
|
|
26
|
+
//
|
|
27
|
+
// --merged handles one unit workspace whose PR has merged: its commits are on
|
|
28
|
+
// the target, so it counts as clean unless it has uncommitted changes or a
|
|
29
|
+
// stash. Its logs stay.
|
|
30
|
+
//
|
|
31
|
+
// Without --apply nothing is touched; the actions are printed. The last line is
|
|
32
|
+
// always a one-line summary. Exit 0 on success, 2 for a bad command.
|
|
33
|
+
|
|
34
|
+
import { execFileSync } from 'node:child_process'
|
|
35
|
+
import { existsSync, lstatSync, readdirSync, rmdirSync, rmSync, statSync, statfsSync } from 'node:fs'
|
|
36
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
37
|
+
|
|
38
|
+
import { isMainModule } from '../../engineering-runtime/scripts/main-module.mjs'
|
|
39
|
+
|
|
40
|
+
export const DEFAULT_OLDER_THAN_DAYS = 3
|
|
41
|
+
export const DEFAULT_LOG_DAYS = 30
|
|
42
|
+
// Records live near the top of a run: task-plan.json, exploration/, sources/,
|
|
43
|
+
// reviews/<round>/review.json.
|
|
44
|
+
export const RECORD_MAX_DEPTH = 4
|
|
45
|
+
export const RECORD_MAX_BYTES = 1024 * 1024
|
|
46
|
+
export const EVIDENCE_MAX_BYTES = 20 * 1024 * 1024
|
|
47
|
+
const RECORD_EXTENSIONS = ['.json', '.jsonl', '.md']
|
|
48
|
+
const EVIDENCE_EXTENSIONS = ['.log', '.txt', '.json', '.jsonl', '.md', '.out', '.err']
|
|
49
|
+
// Directories that only ever hold downloads or build output.
|
|
50
|
+
export const CACHE_DIRS = new Set([
|
|
51
|
+
'node_modules', '.cache', 'cache', 'caches', 'xdg-cache', '.gradle', '.npm', '.pnpm-store', '.m2', '.android',
|
|
52
|
+
'android-sdk', 'sdk', 'system-images', 'build', 'dist', '.cxx', '.next', '.turbo', 'browsers',
|
|
53
|
+
'playwright-browsers', 'ms-playwright', '.venv', 'venv', '__pycache__', 'DerivedData', 'Pods',
|
|
54
|
+
])
|
|
55
|
+
// A non-Git folder with one of these at its root is a copy of a repository:
|
|
56
|
+
// inside it, only logs and text under an evidence folder count as evidence.
|
|
57
|
+
const LOCKFILES = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lockb', 'uv.lock', 'poetry.lock', 'Cargo.lock', 'go.sum', 'Gemfile.lock']
|
|
58
|
+
const EVIDENCE_DIRS = new Set(['test-results', 'logs', 'log', 'reports', 'artifacts', 'playwright-report'])
|
|
59
|
+
const DAY_MS = 24 * 60 * 60 * 1000
|
|
60
|
+
|
|
61
|
+
export class CleanupError extends Error {}
|
|
62
|
+
|
|
63
|
+
function git(dir, args) {
|
|
64
|
+
return execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 256 * 1024 * 1024 })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// What unsaved work a Git workspace holds. `null` when Git cannot read it.
|
|
68
|
+
export function workspaceState(dir) {
|
|
69
|
+
try {
|
|
70
|
+
const changed = git(dir, ['status', '--porcelain']).split('\n').filter(Boolean).length
|
|
71
|
+
const unpushed = Number(git(dir, ['rev-list', '--count', 'HEAD', '--branches', '--not', '--remotes']).trim())
|
|
72
|
+
const stashed = git(dir, ['stash', 'list']).split('\n').filter(Boolean).length
|
|
73
|
+
return { changed, unpushed, stashed }
|
|
74
|
+
} catch {
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const isGitWorkspace = (dir) => existsSync(join(dir, '.git'))
|
|
80
|
+
const isCacheDir = (name) => CACHE_DIRS.has(name) || name.endsWith('.avd')
|
|
81
|
+
const isEvidenceName = (name) => EVIDENCE_EXTENSIONS.some((ext) => name.endsWith(ext)) || /logcat/i.test(name)
|
|
82
|
+
const isLogName = (name) => name.endsWith('.log') || /logcat/i.test(name)
|
|
83
|
+
const isSourceCopy = (dir) => LOCKFILES.some((f) => existsSync(join(dir, f)))
|
|
84
|
+
|
|
85
|
+
// Entering a repository copy starts fresh: only evidence folders inside it count.
|
|
86
|
+
function enterDir(ctx, name, path) {
|
|
87
|
+
if (isSourceCopy(path)) return { sourceCopy: true, inEvidenceDir: false }
|
|
88
|
+
return { sourceCopy: ctx.sourceCopy, inEvidenceDir: ctx.inEvidenceDir || EVIDENCE_DIRS.has(name) }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function describe(state) {
|
|
92
|
+
const parts = []
|
|
93
|
+
if (state.changed) parts.push(`${state.changed} uncommitted file(s)`)
|
|
94
|
+
if (state.unpushed) parts.push(`${state.unpushed} unpushed commit(s)`)
|
|
95
|
+
if (state.stashed) parts.push(`${state.stashed} stash(es)`)
|
|
96
|
+
return parts.join(', ')
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// What happens to one file: kept as a record, kept as a log, or deleted.
|
|
100
|
+
function fileFate(name, path, ctx) {
|
|
101
|
+
if (ctx.tracked?.has(path)) return 'delete'
|
|
102
|
+
const size = statSync(path).size
|
|
103
|
+
const isRecord = !ctx.inClone && !ctx.hidden && ctx.depth <= RECORD_MAX_DEPTH
|
|
104
|
+
&& RECORD_EXTENSIONS.some((ext) => name.endsWith(ext)) && size <= RECORD_MAX_BYTES
|
|
105
|
+
if (isRecord) return 'record'
|
|
106
|
+
const evidence = ctx.sourceCopy && !ctx.inEvidenceDir ? isLogName(name) : isEvidenceName(name)
|
|
107
|
+
if (ctx.keepLogs && evidence && size <= EVIDENCE_MAX_BYTES) return 'log'
|
|
108
|
+
return 'delete'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Actions for one directory. Returns { actions, kept, logs }; a directory with
|
|
112
|
+
// nothing kept collapses into a single delete.
|
|
113
|
+
function sweep(dir, ctx) {
|
|
114
|
+
const actions = []
|
|
115
|
+
let kept = false
|
|
116
|
+
let logs = 0
|
|
117
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
118
|
+
const path = join(dir, entry.name)
|
|
119
|
+
if (entry.isDirectory()) {
|
|
120
|
+
if (isCacheDir(entry.name) || (ctx.inClone && entry.name === '.git')) {
|
|
121
|
+
actions.push({ kind: 'delete', path })
|
|
122
|
+
continue
|
|
123
|
+
}
|
|
124
|
+
if (!ctx.inClone && isGitWorkspace(path)) {
|
|
125
|
+
const action = workspaceAction(path, { keepLogs: ctx.keepLogs, depth: ctx.depth + 1 })
|
|
126
|
+
actions.push(action)
|
|
127
|
+
logs += action.logs ?? 0
|
|
128
|
+
if (action.kind !== 'delete') kept = true
|
|
129
|
+
continue
|
|
130
|
+
}
|
|
131
|
+
const sub = sweep(path, {
|
|
132
|
+
...ctx,
|
|
133
|
+
depth: ctx.depth + 1,
|
|
134
|
+
hidden: ctx.hidden || entry.name.startsWith('.'),
|
|
135
|
+
...enterDir(ctx, entry.name, path),
|
|
136
|
+
})
|
|
137
|
+
if (sub.kept) {
|
|
138
|
+
actions.push(...sub.actions)
|
|
139
|
+
kept = true
|
|
140
|
+
logs += sub.logs
|
|
141
|
+
} else {
|
|
142
|
+
actions.push({ kind: 'delete', path })
|
|
143
|
+
}
|
|
144
|
+
} else if (entry.isFile()) {
|
|
145
|
+
const fate = fileFate(entry.name, path, ctx)
|
|
146
|
+
if (fate === 'delete') actions.push({ kind: 'delete', path })
|
|
147
|
+
else {
|
|
148
|
+
kept = true
|
|
149
|
+
if (fate === 'log') logs++
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
actions.push({ kind: 'delete', path })
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { actions, kept, logs }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const zList = (out) => out.split('\0').filter(Boolean)
|
|
159
|
+
|
|
160
|
+
export function workspaceAction(dir, { merged = false, keepLogs = true, depth = 1 } = {}) {
|
|
161
|
+
const state = workspaceState(dir)
|
|
162
|
+
if (!state) return { kind: 'keep', path: dir, reason: 'Git cannot read this workspace', deletes: [], logs: 0 }
|
|
163
|
+
const unsaved = { ...state, unpushed: merged ? 0 : state.unpushed }
|
|
164
|
+
const ctx = { depth, hidden: false, inClone: true, keepLogs }
|
|
165
|
+
if (!unsaved.changed && !unsaved.unpushed && !unsaved.stashed) {
|
|
166
|
+
const tracked = new Set(zList(git(dir, ['ls-files', '-z'])).map((p) => join(dir, p)))
|
|
167
|
+
const sub = sweep(dir, { ...ctx, tracked })
|
|
168
|
+
const reason = merged ? 'merged and clean' : 'clean and pushed'
|
|
169
|
+
if (!sub.kept) return { kind: 'delete', path: dir, reason, deletes: [], logs: 0 }
|
|
170
|
+
return { kind: 'sweep', path: dir, reason: `${reason}; keeps ${sub.logs} log file(s)`, deletes: sub.actions, logs: sub.logs }
|
|
171
|
+
}
|
|
172
|
+
// Only git-ignored paths are fair game; tracked and untracked files are work.
|
|
173
|
+
const deletes = []
|
|
174
|
+
let logs = 0
|
|
175
|
+
for (const rel of zList(git(dir, ['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z']))) {
|
|
176
|
+
const path = join(dir, rel)
|
|
177
|
+
if (!existsSync(path)) continue
|
|
178
|
+
const name = rel.replace(/\/$/, '').split('/').pop()
|
|
179
|
+
if (lstatSync(path).isDirectory()) {
|
|
180
|
+
if (isCacheDir(name)) { deletes.push({ kind: 'delete', path }); continue }
|
|
181
|
+
const sub = sweep(path, { ...ctx, depth: depth + rel.split('/').length, ...enterDir({ ...ctx, sourceCopy: false, inEvidenceDir: false }, name, path) })
|
|
182
|
+
if (sub.kept) { deletes.push(...sub.actions); logs += sub.logs } else deletes.push({ kind: 'delete', path })
|
|
183
|
+
} else if (fileFate(name, path, ctx) === 'delete') {
|
|
184
|
+
deletes.push({ kind: 'delete', path })
|
|
185
|
+
} else {
|
|
186
|
+
logs++
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { kind: 'strip', path: dir, reason: `keeps ${describe(unsaved)} and ${logs} log file(s); removes ignored downloads`, deletes, logs }
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function lastActive(runDir) {
|
|
193
|
+
const plan = join(runDir, 'task-plan.json')
|
|
194
|
+
return (existsSync(plan) ? statSync(plan) : statSync(runDir)).mtimeMs
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function planSweep({ repo, olderThanDays = DEFAULT_OLDER_THAN_DAYS, logDays = DEFAULT_LOG_DAYS, now = Date.now() }) {
|
|
198
|
+
const root = join(repo, '.resolve-issues', 'rush')
|
|
199
|
+
if (!existsSync(root)) return { root, runs: [] }
|
|
200
|
+
const runs = []
|
|
201
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
202
|
+
if (!entry.isDirectory()) continue
|
|
203
|
+
const dir = join(root, entry.name)
|
|
204
|
+
const idleDays = (now - lastActive(dir)) / DAY_MS
|
|
205
|
+
if (idleDays < olderThanDays) {
|
|
206
|
+
runs.push({ run: entry.name, dir, idleDays, stage: 'active', actions: [], logs: 0 })
|
|
207
|
+
continue
|
|
208
|
+
}
|
|
209
|
+
const keepLogs = idleDays < logDays
|
|
210
|
+
const result = sweep(dir, { depth: 1, hidden: false, inClone: false, keepLogs })
|
|
211
|
+
runs.push({ run: entry.name, dir, idleDays, stage: keepLogs ? 'keep-logs' : 'records-only', actions: result.actions, logs: result.logs })
|
|
212
|
+
}
|
|
213
|
+
runs.sort((a, b) => a.run.localeCompare(b.run))
|
|
214
|
+
return { root, runs }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function planMerged(workspace) {
|
|
218
|
+
const dir = resolve(workspace)
|
|
219
|
+
if (!dir.split(sep).includes('.resolve-issues')) {
|
|
220
|
+
throw new CleanupError(`--merged only removes workspaces under a .resolve-issues directory: ${dir}`)
|
|
221
|
+
}
|
|
222
|
+
if (!existsSync(dir) || !lstatSync(dir).isDirectory() || !isGitWorkspace(dir)) {
|
|
223
|
+
throw new CleanupError(`not a Git workspace: ${dir}`)
|
|
224
|
+
}
|
|
225
|
+
return workspaceAction(dir, { merged: true, keepLogs: true })
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Remove directories left empty under `dir` (bottom-up), and `dir` itself.
|
|
229
|
+
function pruneEmpty(dir) {
|
|
230
|
+
if (!existsSync(dir) || !lstatSync(dir).isDirectory()) return
|
|
231
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
232
|
+
if (entry.isDirectory()) pruneEmpty(join(dir, entry.name))
|
|
233
|
+
}
|
|
234
|
+
if (readdirSync(dir).length === 0) rmdirSync(dir)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Delete one path. Package stores (pnpm, Gradle) mark their files and folders
|
|
238
|
+
// read-only, so on a permission failure grant the owner write access and retry.
|
|
239
|
+
// Returns an error message, or null on success.
|
|
240
|
+
function remove(path) {
|
|
241
|
+
try {
|
|
242
|
+
rmSync(path, { recursive: true, force: true })
|
|
243
|
+
return null
|
|
244
|
+
} catch {
|
|
245
|
+
try {
|
|
246
|
+
execFileSync('chmod', ['u+w', dirname(path)], { stdio: 'ignore' })
|
|
247
|
+
execFileSync('chmod', ['-R', 'u+w', path], { stdio: 'ignore' })
|
|
248
|
+
rmSync(path, { recursive: true, force: true })
|
|
249
|
+
return null
|
|
250
|
+
} catch (error) {
|
|
251
|
+
return `${path}: ${error.code ?? error.message}`
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Apply one action; returns the paths it could not remove.
|
|
257
|
+
export function applyAction(action) {
|
|
258
|
+
const failures = []
|
|
259
|
+
const del = (path) => {
|
|
260
|
+
const failure = remove(path)
|
|
261
|
+
if (failure) failures.push(failure)
|
|
262
|
+
}
|
|
263
|
+
if (action.kind === 'delete') del(action.path)
|
|
264
|
+
else if (action.kind === 'sweep' || action.kind === 'strip') {
|
|
265
|
+
for (const d of action.deletes) del(d.path)
|
|
266
|
+
if (action.kind === 'sweep' && failures.length === 0) pruneEmpty(action.path)
|
|
267
|
+
}
|
|
268
|
+
return failures
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const deletionCount = (actions) => actions.reduce((n, a) => n + (a.kind === 'delete' ? 1 : (a.deletes?.length ?? 0)), 0)
|
|
272
|
+
|
|
273
|
+
function freeBytes(dir) {
|
|
274
|
+
try {
|
|
275
|
+
const s = statfsSync(dir)
|
|
276
|
+
return s.bavail * s.bsize
|
|
277
|
+
} catch {
|
|
278
|
+
return null
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const gigabytes = (bytes) => `${(bytes / 1e9).toFixed(1)} GB`
|
|
283
|
+
|
|
284
|
+
function parseArgs(argv) {
|
|
285
|
+
const usage = 'usage: cleanup-runs.mjs [--repo <dir>] [--older-than-days <n>] [--log-days <n>] [--apply] | --merged <unit-workspace> [--apply]'
|
|
286
|
+
const opts = { repo: process.cwd(), olderThanDays: DEFAULT_OLDER_THAN_DAYS, logDays: DEFAULT_LOG_DAYS, apply: false, merged: null }
|
|
287
|
+
const days = (value) => {
|
|
288
|
+
const n = Number(value)
|
|
289
|
+
if (!Number.isFinite(n) || n < 0) throw new CleanupError(usage)
|
|
290
|
+
return n
|
|
291
|
+
}
|
|
292
|
+
for (let i = 0; i < argv.length; i++) {
|
|
293
|
+
const arg = argv[i]
|
|
294
|
+
if (arg === '--apply') opts.apply = true
|
|
295
|
+
else if (arg === '--repo' && argv[i + 1]) opts.repo = argv[++i]
|
|
296
|
+
else if (arg === '--merged' && argv[i + 1]) opts.merged = argv[++i]
|
|
297
|
+
else if (arg === '--older-than-days' && argv[i + 1]) opts.olderThanDays = days(argv[++i])
|
|
298
|
+
else if (arg === '--log-days' && argv[i + 1]) opts.logDays = days(argv[++i])
|
|
299
|
+
else throw new CleanupError(usage)
|
|
300
|
+
}
|
|
301
|
+
if (opts.logDays < opts.olderThanDays) throw new CleanupError('--log-days must be at least --older-than-days')
|
|
302
|
+
return opts
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function describeAction(a, base) {
|
|
306
|
+
const extra = a.deletes?.length ? `; ${a.deletes.length} path(s) to delete` : ''
|
|
307
|
+
return `${a.kind.padEnd(6)} ${relative(base, a.path) || '.'}${a.reason ? ` (${a.reason}${extra})` : ''}`
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function run(opts, out) {
|
|
311
|
+
const base = opts.merged ? resolve(opts.merged, '..') : opts.repo
|
|
312
|
+
const before = opts.apply ? freeBytes(base) : null
|
|
313
|
+
let actions
|
|
314
|
+
let summary
|
|
315
|
+
if (opts.merged) {
|
|
316
|
+
const action = planMerged(opts.merged)
|
|
317
|
+
out(describeAction(action, base))
|
|
318
|
+
actions = [action]
|
|
319
|
+
summary = `${action.kind} ${action.path}`
|
|
320
|
+
} else {
|
|
321
|
+
const plan = planSweep({ repo: resolve(opts.repo), olderThanDays: opts.olderThanDays, logDays: opts.logDays })
|
|
322
|
+
actions = []
|
|
323
|
+
let logs = 0
|
|
324
|
+
for (const r of plan.runs) {
|
|
325
|
+
const idle = `idle ${r.idleDays.toFixed(1)} days`
|
|
326
|
+
if (r.stage === 'active') {
|
|
327
|
+
out(`run ${r.run} (${idle}): skipped, used within ${opts.olderThanDays} days`)
|
|
328
|
+
continue
|
|
329
|
+
}
|
|
330
|
+
const note = r.stage === 'records-only' ? `records only, past ${opts.logDays} days` : `keeps records and ${r.logs} log file(s)`
|
|
331
|
+
out(`run ${r.run} (${idle}): ${note}${r.actions.length ? '' : '; nothing to remove'}`)
|
|
332
|
+
for (const a of r.actions) out(` ${describeAction(a, r.dir)}`)
|
|
333
|
+
actions.push(...r.actions)
|
|
334
|
+
logs += r.logs
|
|
335
|
+
}
|
|
336
|
+
const swept = plan.runs.filter((r) => r.stage !== 'active').length
|
|
337
|
+
const count = (kind) => actions.filter((a) => a.kind === kind).length
|
|
338
|
+
summary = `${swept} idle run(s), ${plan.runs.length - swept} active; ${deletionCount(actions)} path(s) deleted, ${count('sweep')} clean clone(s) emptied, ${count('strip')} clone(s) with work stripped, ${count('keep')} unreadable kept; ${logs} log file(s) kept`
|
|
339
|
+
}
|
|
340
|
+
if (!opts.apply) {
|
|
341
|
+
out(`cleanup-runs: dry run, nothing removed; ${summary}. Rerun with --apply.`)
|
|
342
|
+
return
|
|
343
|
+
}
|
|
344
|
+
const failures = actions.flatMap((action) => applyAction(action))
|
|
345
|
+
for (const failure of failures) out(` could not remove ${failure}`)
|
|
346
|
+
if (!opts.merged) {
|
|
347
|
+
try {
|
|
348
|
+
git(resolve(opts.repo), ['worktree', 'prune'])
|
|
349
|
+
} catch {}
|
|
350
|
+
}
|
|
351
|
+
const after = freeBytes(base)
|
|
352
|
+
const freed = before !== null && after !== null ? `; freed ${gigabytes(Math.max(0, after - before))}` : ''
|
|
353
|
+
const failed = failures.length ? `; ${failures.length} path(s) could not be removed` : ''
|
|
354
|
+
out(`cleanup-runs: ${summary}${freed}${failed}`)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (isMainModule(import.meta.url)) {
|
|
358
|
+
try {
|
|
359
|
+
run(parseArgs(process.argv.slice(2)), (line) => process.stdout.write(`${line}\n`))
|
|
360
|
+
} catch (error) {
|
|
361
|
+
process.stderr.write(`${error instanceof CleanupError ? error.message : error.stack}\n`)
|
|
362
|
+
process.exitCode = 2
|
|
363
|
+
}
|
|
364
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
4
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, utimesSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { dirname, join } from 'node:path'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
import { EVIDENCE_MAX_BYTES, planSweep } from './cleanup-runs.mjs'
|
|
10
|
+
|
|
11
|
+
const script = join(dirname(fileURLToPath(import.meta.url)), 'cleanup-runs.mjs')
|
|
12
|
+
const DAY_MS = 24 * 60 * 60 * 1000
|
|
13
|
+
|
|
14
|
+
const git = (dir, ...args) => execFileSync('git', ['-C', dir, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
|
|
15
|
+
|
|
16
|
+
function write(path, content = 'x') {
|
|
17
|
+
mkdirSync(dirname(path), { recursive: true })
|
|
18
|
+
writeFileSync(path, content)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A clone of the remote at `dir`, with ignored installs, caches, and a test log.
|
|
22
|
+
function clone(remote, dir) {
|
|
23
|
+
git(dirname(dir), 'clone', '--quiet', remote, dir)
|
|
24
|
+
git(dir, 'config', 'user.email', 't@example.com')
|
|
25
|
+
git(dir, 'config', 'user.name', 'T')
|
|
26
|
+
write(join(dir, 'node_modules', 'pkg', 'package.json'), '{}')
|
|
27
|
+
write(join(dir, '.cache', 'sdk', 'system.img'), 'big')
|
|
28
|
+
write(join(dir, 'test-results', 'journey.log'), 'emulator boot failed')
|
|
29
|
+
write(join(dir, 'test-results', 'avd', 'Charge.avd', 'userdata.img'), 'big')
|
|
30
|
+
return dir
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function fixture() {
|
|
34
|
+
const base = mkdtempSync(join(tmpdir(), 'cleanup-runs-'))
|
|
35
|
+
const remote = join(base, 'remote.git')
|
|
36
|
+
const seed = join(base, 'seed')
|
|
37
|
+
execFileSync('git', ['init', '--quiet', '--bare', remote])
|
|
38
|
+
execFileSync('git', ['init', '--quiet', seed])
|
|
39
|
+
git(seed, 'config', 'user.email', 't@example.com')
|
|
40
|
+
git(seed, 'config', 'user.name', 'T')
|
|
41
|
+
write(join(seed, '.gitignore'), 'node_modules/\n.cache/\ntest-results/\n')
|
|
42
|
+
write(join(seed, 'app.js'), 'v1')
|
|
43
|
+
write(join(seed, 'docs', 'README.md'), '# tracked doc')
|
|
44
|
+
git(seed, 'add', '.')
|
|
45
|
+
git(seed, 'commit', '--quiet', '-m', 'seed')
|
|
46
|
+
git(seed, 'push', '--quiet', remote, 'HEAD:main')
|
|
47
|
+
git(remote, 'symbolic-ref', 'HEAD', 'refs/heads/main')
|
|
48
|
+
const repo = join(base, 'repo')
|
|
49
|
+
mkdirSync(repo)
|
|
50
|
+
return { base, remote, repo, rush: join(repo, '.resolve-issues', 'rush') }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function makeRun(rush, name, idleDays) {
|
|
54
|
+
const dir = join(rush, name)
|
|
55
|
+
write(join(dir, 'task-plan.json'), '{}')
|
|
56
|
+
const when = new Date(Date.now() - idleDays * DAY_MS)
|
|
57
|
+
utimesSync(join(dir, 'task-plan.json'), when, when)
|
|
58
|
+
return dir
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const cli = (...args) => spawnSync(process.execPath, [script, ...args], { encoding: 'utf8' })
|
|
62
|
+
const has = (dir, rel) => existsSync(join(dir, rel))
|
|
63
|
+
|
|
64
|
+
test('an idle run keeps records and logs, and loses downloads, caches, and clean source', () => {
|
|
65
|
+
const { remote, repo, rush } = fixture()
|
|
66
|
+
const run = makeRun(rush, 'old', 10)
|
|
67
|
+
write(join(run, 'exploration', 'findings.json'), '{}')
|
|
68
|
+
write(join(run, 'reviews', '1131-r1', 'review.md'), 'ok')
|
|
69
|
+
write(join(run, 'reviews', '1131-r1', 'sandbox', 'sdk', 'system.img'), 'big')
|
|
70
|
+
write(join(run, 'reviews', '1131-r1', 'sandbox', 'worker.log'), 'review log')
|
|
71
|
+
write(join(run, 'diagnoses', '1136', 'deep', 'nested', 'adb.txt'), 'adb not ready')
|
|
72
|
+
write(join(run, '.tmp', 'resume-result.json'), '{}')
|
|
73
|
+
write(join(run, 'jdk17.tar.gz'), 'big')
|
|
74
|
+
mkdirSync(join(run, 'units'), { recursive: true })
|
|
75
|
+
const ws = clone(remote, join(run, 'units', '1132'))
|
|
76
|
+
|
|
77
|
+
const result = cli('--repo', repo, '--apply')
|
|
78
|
+
assert.equal(result.status, 0, result.stderr)
|
|
79
|
+
|
|
80
|
+
for (const kept of ['task-plan.json', 'exploration/findings.json', 'reviews/1131-r1/review.md', 'reviews/1131-r1/sandbox/worker.log', 'diagnoses/1136/deep/nested/adb.txt', '.tmp/resume-result.json']) {
|
|
81
|
+
assert.ok(has(run, kept), `${kept} should be kept`)
|
|
82
|
+
}
|
|
83
|
+
for (const gone of ['reviews/1131-r1/sandbox/sdk', 'jdk17.tar.gz']) assert.ok(!has(run, gone), `${gone} should be removed`)
|
|
84
|
+
|
|
85
|
+
// The clean clone keeps only its logs: no source, .git, installs, caches, or emulator disks.
|
|
86
|
+
assert.ok(has(ws, 'test-results/journey.log'))
|
|
87
|
+
for (const gone of ['app.js', 'docs', '.git', '.gitignore', 'node_modules', '.cache', 'test-results/avd']) assert.ok(!has(ws, gone), `clone ${gone} should be removed`)
|
|
88
|
+
assert.deepEqual(readdirSync(ws), ['test-results'])
|
|
89
|
+
assert.match(result.stdout, /sweep\s+units\/1132 \(clean and pushed; keeps 1 log file\(s\)/)
|
|
90
|
+
assert.match(result.stdout.trim().split('\n').at(-1), /^cleanup-runs: 1 idle run\(s\), 0 active; .*1 clean clone\(s\) emptied.*log file\(s\) kept; freed/)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('a clone with unpushed commits, edits, or a stash keeps its work and logs, and loses ignored downloads', () => {
|
|
94
|
+
const { remote, repo, rush } = fixture()
|
|
95
|
+
const run = makeRun(rush, 'old', 10)
|
|
96
|
+
mkdirSync(join(run, 'units'), { recursive: true })
|
|
97
|
+
|
|
98
|
+
const committed = clone(remote, join(run, 'units', 'committed'))
|
|
99
|
+
write(join(committed, 'app.js'), 'v2')
|
|
100
|
+
git(committed, 'commit', '--quiet', '-am', 'local only')
|
|
101
|
+
|
|
102
|
+
const edited = clone(remote, join(run, 'units', 'edited'))
|
|
103
|
+
write(join(edited, 'new.js'), 'untracked work')
|
|
104
|
+
|
|
105
|
+
const stashed = clone(remote, join(run, 'units', 'stashed'))
|
|
106
|
+
write(join(stashed, 'app.js'), 'stashed work')
|
|
107
|
+
git(stashed, 'stash', '--quiet')
|
|
108
|
+
|
|
109
|
+
const result = cli('--repo', repo, '--apply')
|
|
110
|
+
assert.equal(result.status, 0, result.stderr)
|
|
111
|
+
|
|
112
|
+
assert.equal(git(committed, 'rev-list', '--count', 'HEAD', '--not', '--remotes').trim(), '1')
|
|
113
|
+
assert.ok(has(edited, 'new.js'))
|
|
114
|
+
assert.equal(git(stashed, 'stash', 'list').split('\n').filter(Boolean).length, 1)
|
|
115
|
+
for (const dir of [committed, edited, stashed]) {
|
|
116
|
+
assert.ok(has(dir, 'app.js') && has(dir, 'docs/README.md'), `${dir} keeps tracked files`)
|
|
117
|
+
assert.ok(has(dir, 'test-results/journey.log'), `${dir} keeps its log`)
|
|
118
|
+
for (const gone of ['node_modules', '.cache', 'test-results/avd']) assert.ok(!has(dir, gone), `${dir} ${gone} should be stripped`)
|
|
119
|
+
}
|
|
120
|
+
assert.match(result.stdout, /strip\s+units\/committed \(keeps 1 unpushed commit\(s\) and 1 log file\(s\)/)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
test('past the log window only records remain; clones with work still keep their work', () => {
|
|
124
|
+
const { remote, repo, rush } = fixture()
|
|
125
|
+
const run = makeRun(rush, 'ancient', 40)
|
|
126
|
+
write(join(run, 'reviews', '1131-r1.json'), '{}')
|
|
127
|
+
write(join(run, 'reviews', '1131-r1', 'sandbox', 'worker.log'), 'old log')
|
|
128
|
+
mkdirSync(join(run, 'units'), { recursive: true })
|
|
129
|
+
const clean = clone(remote, join(run, 'units', 'clean'))
|
|
130
|
+
const busy = clone(remote, join(run, 'units', 'busy'))
|
|
131
|
+
write(join(busy, 'app.js'), 'v2')
|
|
132
|
+
git(busy, 'commit', '--quiet', '-am', 'local only')
|
|
133
|
+
|
|
134
|
+
const result = cli('--repo', repo, '--log-days', '30', '--apply')
|
|
135
|
+
assert.equal(result.status, 0, result.stderr)
|
|
136
|
+
assert.match(result.stdout, /records only, past 30 days/)
|
|
137
|
+
assert.ok(has(run, 'reviews/1131-r1.json'))
|
|
138
|
+
assert.ok(!has(run, 'reviews/1131-r1'), 'the old log and its folder go')
|
|
139
|
+
assert.ok(!existsSync(clean), 'a clean clone with no logs left is deleted')
|
|
140
|
+
assert.ok(has(busy, 'app.js'))
|
|
141
|
+
assert.ok(!has(busy, 'test-results'), 'its ignored log goes too')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('text inside a tool cache is not evidence, and an oversized log is dropped', () => {
|
|
145
|
+
const { repo, rush } = fixture()
|
|
146
|
+
const run = makeRun(rush, 'old', 10)
|
|
147
|
+
write(join(run, 'home', '.npm', '_cacache', 'index.json'), '{}')
|
|
148
|
+
write(join(run, 'xdg-cache', 'pnpm', 'metadata.jsonl'), '{}')
|
|
149
|
+
write(join(run, 'builds', 'Pixel.avd', 'config.txt'), 'x')
|
|
150
|
+
write(join(run, 'logs', 'huge.log'), Buffer.alloc(EVIDENCE_MAX_BYTES + 1))
|
|
151
|
+
write(join(run, 'logs', 'small.log'), 'ok')
|
|
152
|
+
|
|
153
|
+
assert.equal(cli('--repo', repo, '--apply').status, 0)
|
|
154
|
+
for (const gone of ['home', 'xdg-cache', 'builds', 'logs/huge.log']) assert.ok(!has(run, gone), `${gone} should be removed`)
|
|
155
|
+
assert.ok(has(run, 'logs/small.log'))
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('a clone hidden inside a dot directory is still protected', () => {
|
|
159
|
+
const { remote, repo, rush } = fixture()
|
|
160
|
+
const run = makeRun(rush, 'old', 10)
|
|
161
|
+
mkdirSync(join(run, '.tmp'), { recursive: true })
|
|
162
|
+
const hidden = clone(remote, join(run, '.tmp', 'wip'))
|
|
163
|
+
write(join(hidden, 'app.js'), 'v2')
|
|
164
|
+
git(hidden, 'commit', '--quiet', '-am', 'local only')
|
|
165
|
+
|
|
166
|
+
assert.equal(cli('--repo', repo, '--apply').status, 0)
|
|
167
|
+
assert.ok(has(hidden, 'app.js'))
|
|
168
|
+
assert.ok(!has(hidden, 'node_modules'))
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
test('a run used recently is left alone, and a dry run removes nothing', () => {
|
|
172
|
+
const { remote, repo, rush } = fixture()
|
|
173
|
+
const active = makeRun(rush, 'active', 1)
|
|
174
|
+
write(join(active, 'units', 'scratch', 'big.img'), 'big')
|
|
175
|
+
const idle = makeRun(rush, 'idle', 10)
|
|
176
|
+
mkdirSync(join(idle, 'units'), { recursive: true })
|
|
177
|
+
clone(remote, join(idle, 'units', 'a'))
|
|
178
|
+
|
|
179
|
+
const dry = cli('--repo', repo)
|
|
180
|
+
assert.equal(dry.status, 0, dry.stderr)
|
|
181
|
+
assert.ok(has(idle, 'units/a/node_modules'))
|
|
182
|
+
assert.match(dry.stdout.trim().split('\n').at(-1), /dry run, nothing removed.*Rerun with --apply/)
|
|
183
|
+
|
|
184
|
+
assert.equal(cli('--repo', repo, '--older-than-days', '3', '--apply').status, 0)
|
|
185
|
+
assert.ok(has(active, 'units/scratch/big.img'))
|
|
186
|
+
assert.ok(!has(idle, 'units/a/node_modules'))
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('runs are staged by task-plan.json age', () => {
|
|
190
|
+
const { repo, rush } = fixture()
|
|
191
|
+
makeRun(rush, 'a-two', 2)
|
|
192
|
+
makeRun(rush, 'b-ten', 10)
|
|
193
|
+
makeRun(rush, 'c-forty', 40)
|
|
194
|
+
const stages = planSweep({ repo, olderThanDays: 3, logDays: 30 }).runs.map((r) => [r.run, r.stage])
|
|
195
|
+
assert.deepEqual(stages, [['a-two', 'active'], ['b-ten', 'keep-logs'], ['c-forty', 'records-only']])
|
|
196
|
+
assert.deepEqual(planSweep({ repo: join(repo, 'missing') }).runs, [])
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
test('--merged empties a merged clean workspace to its logs, even with commits that look unpushed', () => {
|
|
200
|
+
const { remote, rush } = fixture()
|
|
201
|
+
const run = makeRun(rush, 'now', 0)
|
|
202
|
+
mkdirSync(join(run, 'units'), { recursive: true })
|
|
203
|
+
const ws = clone(remote, join(run, 'units', 'merged'))
|
|
204
|
+
write(join(ws, 'app.js'), 'v2')
|
|
205
|
+
git(ws, 'commit', '--quiet', '-am', 'squash-merged upstream')
|
|
206
|
+
|
|
207
|
+
const result = cli('--merged', ws, '--apply')
|
|
208
|
+
assert.equal(result.status, 0, result.stderr)
|
|
209
|
+
assert.deepEqual(readdirSync(ws), ['test-results'])
|
|
210
|
+
assert.ok(has(ws, 'test-results/journey.log'))
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('--merged keeps uncommitted edits and refuses paths outside .resolve-issues', () => {
|
|
214
|
+
const { base, remote, rush } = fixture()
|
|
215
|
+
const run = makeRun(rush, 'now', 0)
|
|
216
|
+
mkdirSync(join(run, 'units'), { recursive: true })
|
|
217
|
+
const ws = clone(remote, join(run, 'units', 'dirty'))
|
|
218
|
+
write(join(ws, 'app.js'), 'uncommitted')
|
|
219
|
+
|
|
220
|
+
assert.equal(cli('--merged', ws, '--apply').status, 0)
|
|
221
|
+
assert.ok(has(ws, 'app.js') && has(ws, 'test-results/journey.log'))
|
|
222
|
+
assert.ok(!has(ws, 'node_modules'))
|
|
223
|
+
|
|
224
|
+
const outside = clone(remote, join(base, 'elsewhere'))
|
|
225
|
+
const refused = cli('--merged', outside, '--apply')
|
|
226
|
+
assert.equal(refused.status, 2)
|
|
227
|
+
assert.match(refused.stderr, /only removes workspaces under a \.resolve-issues directory/)
|
|
228
|
+
assert.ok(existsSync(outside))
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('a bad command exits 2 with usage', () => {
|
|
232
|
+
for (const args of [['--older-than-days', 'soon'], ['--bogus'], ['--repo'], ['--log-days', '-1']]) {
|
|
233
|
+
const result = cli(...args)
|
|
234
|
+
assert.equal(result.status, 2)
|
|
235
|
+
assert.match(result.stderr, /^usage: cleanup-runs\.mjs/)
|
|
236
|
+
}
|
|
237
|
+
const inverted = cli('--older-than-days', '10', '--log-days', '5')
|
|
238
|
+
assert.equal(inverted.status, 2)
|
|
239
|
+
assert.match(inverted.stderr, /--log-days must be at least --older-than-days/)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
test('in a non-Git copy of a repository, only logs and text under evidence folders are kept', () => {
|
|
243
|
+
const { repo, rush } = fixture()
|
|
244
|
+
const run = makeRun(rush, 'old', 10)
|
|
245
|
+
const copy = join(run, 'units', '1132', 'test-results', 'packet', 'build-x', 'workspace')
|
|
246
|
+
write(join(copy, 'pnpm-lock.yaml'), 'lock')
|
|
247
|
+
write(join(copy, 'package.json'), '{}')
|
|
248
|
+
write(join(copy, 'docs', 'design.md'), '# copied source doc')
|
|
249
|
+
write(join(copy, 'build.log'), 'gradle failed')
|
|
250
|
+
write(join(copy, 'test-results', 'summary.json'), '{}')
|
|
251
|
+
write(join(run, 'units', '1132', 'test-results', 'packet', 'gradle', 'caches', 'meta.json'), '{}')
|
|
252
|
+
write(join(run, 'units', '1132', 'test-results', 'packet', 'result.json'), '{}')
|
|
253
|
+
|
|
254
|
+
assert.equal(cli('--repo', repo, '--apply').status, 0)
|
|
255
|
+
for (const kept of ['build.log', 'test-results/summary.json']) assert.ok(has(copy, kept), `${kept} should be kept`)
|
|
256
|
+
for (const gone of ['package.json', 'pnpm-lock.yaml', 'docs']) assert.ok(!has(copy, gone), `${gone} should be removed`)
|
|
257
|
+
assert.ok(!has(run, 'units/1132/test-results/packet/gradle'))
|
|
258
|
+
assert.ok(has(run, 'units/1132/test-results/packet/result.json'))
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test('read-only package stores are removed, not left to abort the run', () => {
|
|
262
|
+
const { repo, rush } = fixture()
|
|
263
|
+
const run = makeRun(rush, 'old', 10)
|
|
264
|
+
const store = join(run, 'artifacts', 'pnpm-v11', 'v11')
|
|
265
|
+
write(join(store, 'files', '61', 'abc'), 'blob')
|
|
266
|
+
write(join(store, 'index.db'), 'db')
|
|
267
|
+
for (const p of [join(store, 'files', '61', 'abc'), join(store, 'index.db')]) chmodSync(p, 0o444)
|
|
268
|
+
write(join(run, 'artifacts', 'pnpm-tuple', 'store', 'blob'), 'x')
|
|
269
|
+
write(join(run, 'artifacts', 'pnpm-tuple', 'install.log'), 'kept log')
|
|
270
|
+
for (const d of [join(store, 'files', '61'), join(store, 'files'), store, join(run, 'artifacts', 'pnpm-tuple', 'store'), join(run, 'artifacts', 'pnpm-tuple')]) chmodSync(d, 0o555)
|
|
271
|
+
write(join(run, 'zz', 'worker.log'), 'kept')
|
|
272
|
+
|
|
273
|
+
const result = cli('--repo', repo, '--apply')
|
|
274
|
+
assert.equal(result.status, 0, result.stderr)
|
|
275
|
+
assert.ok(!has(run, 'artifacts/pnpm-v11'), 'the read-only store is gone')
|
|
276
|
+
assert.ok(!has(run, 'artifacts/pnpm-tuple/store'), 'a store inside a read-only folder is gone')
|
|
277
|
+
assert.ok(has(run, 'artifacts/pnpm-tuple/install.log'), 'its sibling log stays')
|
|
278
|
+
assert.ok(has(run, 'zz/worker.log'), 'later paths are still processed')
|
|
279
|
+
assert.doesNotMatch(result.stdout, /could not be removed/)
|
|
280
|
+
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Thin wrapper: canonical ownership lives in harness-runtime.
|
|
2
|
+
export * from '../../harness-runtime/discover-models.mjs'
|
|
3
|
+
|
|
4
|
+
import { runCli } from '../../harness-runtime/discover-models.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
|
+
}
|