@sockulags/agent-os 0.15.0 → 0.17.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 +105 -59
- package/cli/doctor.mjs +351 -0
- package/cli/index.mjs +328 -151
- package/cli/index.test.mjs +436 -9
- package/package.json +5 -6
- package/plugins/agent-os-core/.claude-plugin/plugin.json +18 -0
- package/plugins/agent-os-core/.codex-plugin/plugin.json +24 -0
- package/plugins/agent-os-core/skills/capture-intent/SKILL.md +68 -0
- package/plugins/agent-os-core/skills/capture-intent/references/intent-template.md +47 -0
- package/plugins/agent-os-core/skills/explain-work/SKILL.md +42 -0
- package/{skills → plugins/agent-os-core/skills}/list-skills/SKILL.md +16 -7
- package/{skills → plugins/agent-os-core/skills}/plain-voice/SKILL.md +7 -4
- package/plugins/agent-os-core/skills/plan-work/SKILL.md +151 -0
- package/{skills → plugins/agent-os-core/skills}/plan-work/references/elicitation.md +7 -3
- package/plugins/agent-os-core/skills/plan-work/references/spec-template.md +65 -0
- package/plugins/agent-os-core/skills/record-lesson/SKILL.md +47 -0
- package/{skills → plugins/agent-os-core/skills}/scope-guard/SKILL.md +11 -6
- package/{skills → plugins/agent-os-core/skills}/verify-before-done/SKILL.md +6 -2
- package/plugins/agent-os-dev/.claude-plugin/plugin.json +18 -0
- package/plugins/agent-os-dev/.codex-plugin/plugin.json +24 -0
- package/plugins/agent-os-dev/hooks/hooks.json +42 -0
- package/{skills → plugins/agent-os-dev/skills}/batch-work/SKILL.md +6 -2
- package/{skills → plugins/agent-os-dev/skills}/check-work/SKILL.md +33 -14
- package/{skills/deliver-work/workflow.md → plugins/agent-os-dev/skills/deliver-work/SKILL.md} +126 -57
- package/plugins/agent-os-dev/skills/deliver-work/references/work-records.md +20 -0
- package/plugins/agent-os-dev/skills/design-work/SKILL.md +160 -0
- package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.mjs +233 -0
- package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.test.mjs +73 -0
- package/plugins/agent-os-dev/skills/diagnose-before-fix/SKILL.md +29 -0
- package/{skills → plugins/agent-os-dev/skills}/dispatch-next/SKILL.md +11 -3
- package/plugins/agent-os-dev/skills/init-agent-os/SKILL.md +131 -0
- package/plugins/agent-os-dev/skills/init-agent-os/policy.md +91 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/guards.md +40 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/repository-init.md +115 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/review-template.md +35 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/workflow-template.md +80 -0
- package/plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs +187 -0
- package/plugins/agent-os-dev/skills/init-agent-os/templates/agent-review.yml +59 -0
- package/plugins/agent-os-dev/skills/init-agent-os/templates/lint-intents.yml +30 -0
- package/{skills → plugins/agent-os-dev/skills}/proportional-testing/SKILL.md +1 -1
- package/plugins/agent-os-dev/skills/quality-ratchet/SKILL.md +104 -0
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/project-controls.md +31 -3
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.mjs +145 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.test.mjs +158 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.mjs +372 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.test.mjs +138 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.mjs +322 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.test.mjs +177 -0
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.mjs +59 -8
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.test.mjs +134 -8
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.mjs +296 -22
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.test.mjs +114 -6
- package/plugins/agent-os-dev/skills/shape-work/SKILL.md +135 -0
- package/plugins/agent-os-dev/skills/shape-work/references/implementation-issues.md +163 -0
- package/{skills/plan-work → plugins/agent-os-dev/skills/shape-work}/references/prototypes.md +9 -10
- package/plugins/agent-os-dev/skills/simplify/SKILL.md +91 -0
- package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.mjs +166 -0
- package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.test.mjs +49 -0
- package/policy.md +57 -30
- package/hooks/hooks.json +0 -17
- package/skills/deliver-work/SKILL.md +0 -12
- package/skills/diagnose-before-fix/SKILL.md +0 -24
- package/skills/explain-work/SKILL.md +0 -28
- package/skills/init-agent-os/SKILL.md +0 -55
- package/skills/init-agent-os/references/repository-init.md +0 -75
- package/skills/init-agent-os/scripts/policy-block.ps1 +0 -87
- package/skills/notice-lesson/SKILL.md +0 -20
- package/skills/plan-work/SKILL.md +0 -100
- package/skills/quality-ratchet/SKILL.md +0 -72
- package/skills/record-lesson/SKILL.md +0 -31
- package/skills/shape-work/SKILL.md +0 -71
- package/skills/shape-work/references/implementation-issues.md +0 -90
- package/skills/shape-work/references/mockups.md +0 -23
- package/skills/simplifier/SKILL.md +0 -35
- package/skills/simplifier-audit/SKILL.md +0 -30
- package/skills/simplifier-review/SKILL.md +0 -40
- package/skills/understand-work/SKILL.md +0 -32
- package/skills/understand-work/agents/openai.yaml +0 -2
- package/skills/writing-skills/SKILL.md +0 -68
- package/skills/writing-skills/agents/openai.yaml +0 -2
- /package/{skills/batch-work → plugins/agent-os-core/skills/capture-intent}/agents/openai.yaml +0 -0
- /package/{skills/deliver-work → plugins/agent-os-core/skills/explain-work}/agents/openai.yaml +0 -0
- /package/{skills/dispatch-next → plugins/agent-os-core/skills/list-skills}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-core/skills}/plain-voice/references/tells.md +0 -0
- /package/{skills/explain-work → plugins/agent-os-core/skills/plan-work}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-core/skills}/plan-work/references/map.md +0 -0
- /package/{skills/init-agent-os → plugins/agent-os-dev/skills/batch-work}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/references/manifest.md +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/manifest-hash.mjs +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/test-manifest-hash.mjs +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/check-work/references/findings.md +0 -0
- /package/{skills/list-skills → plugins/agent-os-dev/skills/deliver-work}/agents/openai.yaml +0 -0
- /package/{skills/plan-work → plugins/agent-os-dev/skills/design-work}/agents/openai.yaml +0 -0
- /package/{skills/record-lesson → plugins/agent-os-dev/skills/dispatch-next}/agents/openai.yaml +0 -0
- /package/{skills/shape-work → plugins/agent-os-dev/skills/init-agent-os}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/proportional-testing/references/strategy.md +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/structure.md +0 -0
- /package/{skills/simplifier-audit → plugins/agent-os-dev/skills/shape-work}/agents/openai.yaml +0 -0
- /package/{skills/simplifier → plugins/agent-os-dev/skills/simplify}/agents/openai.yaml +0 -0
package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/project-controls.md
RENAMED
|
@@ -47,8 +47,23 @@ Use the actual project wrapper and supported command for its operating system.
|
|
|
47
47
|
|
|
48
48
|
Commands are argument arrays, run at the Git root with inherited environment and no implicit shell.
|
|
49
49
|
Use an explicit interpreter for scripts that need one; on Windows prefer Node entrypoints or the
|
|
50
|
-
project's explicitly selected shell for `.cmd` wrappers. The repository configuration is
|
|
51
|
-
|
|
50
|
+
project's explicitly selected shell for `.cmd` wrappers. The repository configuration is executable
|
|
51
|
+
project code, so `check` runs it only after the developer trusts it on that machine:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
node "$QUALITY_RUNNER" trust --root <worktree>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`trust` prints the declared commands and protected files and records trust only after a yes in an
|
|
58
|
+
interactive terminal; it refuses without a TTY, so an agent's shell tool cannot complete it. Trust is
|
|
59
|
+
stored in `~/.agent-os/trusted-controls.json`, keyed by the repository's common Git directory (shared
|
|
60
|
+
by its linked worktrees) and the signature of the policy plus its protected files. Changing
|
|
61
|
+
`.agent-os/quality.json` or a protected file, including through an acknowledged policy change, needs
|
|
62
|
+
trust again. Until then `check` reports the commands as untrusted, runs none of them, and blocks
|
|
63
|
+
delivery. Scripts the commands call but that are not listed in `protectedFiles` can change without
|
|
64
|
+
re-trust. This is a visible prompt and a speed bump for agents, not a tamper-proof boundary.
|
|
65
|
+
Environments with `CI=true` or `CI=1` run the declared controls without a trust record, because a CI
|
|
66
|
+
checkout already runs the repository's own code and cannot answer a prompt.
|
|
52
67
|
|
|
53
68
|
All checks default to advisory and run on every `check`. `required: true` blocks delivery unless the
|
|
54
69
|
command exits zero. Missing tools, timeout, signal termination, and output overflow are distinct
|
|
@@ -69,6 +84,19 @@ line movement. These lexical signals can match comments or strings and can reapp
|
|
|
69
84
|
they do not establish a semantic defect. Review them or delegate exact rules to the project's linter.
|
|
70
85
|
Only rules explicitly listed in `blockSignals` block delivery. Raw LOC and structural counts never do.
|
|
71
86
|
|
|
87
|
+
## Complexity threshold
|
|
88
|
+
|
|
89
|
+
With lizard installed, a project can flag touched functions whose cyclomatic complexity rises above a
|
|
90
|
+
threshold, or new functions above it:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{ "schema": 1, "checks": [], "complexity": { "threshold": 15 }, "blockSignals": ["complexity"] }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Without `"complexity"` in `blockSignals` the result is an advisory `complexity` signal. Functions
|
|
97
|
+
that were already above the threshold and did not grow are never flagged. Without lizard the
|
|
98
|
+
evidence says `unavailable` and nothing is flagged or blocked.
|
|
99
|
+
|
|
72
100
|
The policy itself and repository-relative `protectedFiles` are fingerprinted at entry. Include the
|
|
73
101
|
lint, type, test, architecture, and CI configurations whose weakening should require attention.
|
|
74
102
|
A protected missing file is represented as absent; later creation or deletion changes the signature.
|
|
@@ -122,7 +150,7 @@ node "$QUALITY_RUNNER" check --json
|
|
|
122
150
|
`check` exits 1 on blocked evidence, 0 when all required checks pass, and reports errors as nonzero.
|
|
123
151
|
The default output is concise; `--json` includes per-check status, command, fingerprint, cache reuse,
|
|
124
152
|
measured scope, duration, output, signals, and any policy acknowledgement. The latest full report is
|
|
125
|
-
`<session-state-path>.report.json` under Git metadata and
|
|
153
|
+
`<session-state-path>.report.json` under Git metadata and remains after `finish`; `begin` prints the
|
|
126
154
|
session state path. Treat command output as potentially sensitive when uploading reports.
|
|
127
155
|
|
|
128
156
|
For CI, use a fresh checkout and the same runner and project policy; `check` is the gate. A baseline
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// Optional deterministic analyzers. Agent OS never installs them; when one is missing its evidence
|
|
2
|
+
// is reported as unavailable and the core Node evidence still stands.
|
|
3
|
+
|
|
4
|
+
import { spawnSync } from 'node:child_process'
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import os from 'node:os'
|
|
7
|
+
import path from 'node:path'
|
|
8
|
+
|
|
9
|
+
const LIZARD_LAUNCHERS = [['lizard'], ['python3', '-m', 'lizard'], ['python', '-m', 'lizard']]
|
|
10
|
+
const BATCH_SIZE = 200
|
|
11
|
+
const TIMEOUT_MS = 120000
|
|
12
|
+
|
|
13
|
+
function run(argv, cwd, spawn) {
|
|
14
|
+
return spawn(argv[0], argv.slice(1), {
|
|
15
|
+
cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// `python -m lizard` imports from its working directory first, so a lizard.py in the repository
|
|
20
|
+
// would run. Every lizard process therefore starts in an empty temporary directory and receives
|
|
21
|
+
// absolute file paths.
|
|
22
|
+
function inNeutralDirectory(callback) {
|
|
23
|
+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-lizard-'))
|
|
24
|
+
try {
|
|
25
|
+
return callback(directory)
|
|
26
|
+
} finally {
|
|
27
|
+
fs.rmSync(directory, { recursive: true, force: true })
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function findLizard({ spawn = spawnSync } = {}) {
|
|
32
|
+
return inNeutralDirectory((directory) => {
|
|
33
|
+
for (const launcher of LIZARD_LAUNCHERS) {
|
|
34
|
+
try {
|
|
35
|
+
if (run([...launcher, '--version'], directory, spawn).status === 0) return launcher
|
|
36
|
+
} catch { /* try the next launcher */ }
|
|
37
|
+
}
|
|
38
|
+
return null
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function csvFields(line) {
|
|
43
|
+
const fields = []
|
|
44
|
+
let field = ''
|
|
45
|
+
let quoted = false
|
|
46
|
+
for (let index = 0; index < line.length; index += 1) {
|
|
47
|
+
const char = line[index]
|
|
48
|
+
if (quoted) {
|
|
49
|
+
if (char === '"' && line[index + 1] === '"') { field += '"'; index += 1 }
|
|
50
|
+
else if (char === '"') quoted = false
|
|
51
|
+
else field += char
|
|
52
|
+
} else if (char === '"') quoted = true
|
|
53
|
+
else if (char === ',') { fields.push(field); field = '' }
|
|
54
|
+
else field += char
|
|
55
|
+
}
|
|
56
|
+
fields.push(field)
|
|
57
|
+
return fields
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// lizard --csv columns: NLOC, CCN, tokens, parameters, length, location, file, function,
|
|
61
|
+
// long name, start line, end line.
|
|
62
|
+
export function parseLizardCsv(text) {
|
|
63
|
+
return text.split(/\r?\n/).filter(Boolean).flatMap((line) => {
|
|
64
|
+
const fields = csvFields(line)
|
|
65
|
+
const ccn = Number(fields[1])
|
|
66
|
+
if (fields.length < 11 || !Number.isInteger(ccn)) return []
|
|
67
|
+
return [{
|
|
68
|
+
file: fields[6].replaceAll('\\', '/'),
|
|
69
|
+
function: fields[7],
|
|
70
|
+
line: Number(fields[9]),
|
|
71
|
+
ccn,
|
|
72
|
+
nloc: Number(fields[0])
|
|
73
|
+
}]
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Runs lizard on repository-relative files under cwd. Returns null when lizard is unavailable.
|
|
78
|
+
export function lizardFunctions(cwd, files, { launcher = findLizard(), spawn = spawnSync } = {}) {
|
|
79
|
+
if (!launcher) return null
|
|
80
|
+
const root = path.resolve(cwd)
|
|
81
|
+
const relative = (file) => path.isAbsolute(file) ? path.relative(root, file).replaceAll('\\', '/') : file
|
|
82
|
+
return inNeutralDirectory((directory) => {
|
|
83
|
+
const functions = []
|
|
84
|
+
for (let start = 0; start < files.length; start += BATCH_SIZE) {
|
|
85
|
+
const batch = files.slice(start, start + BATCH_SIZE).map((file) => path.join(root, file))
|
|
86
|
+
const result = run([...launcher, '--csv', ...batch], directory, spawn)
|
|
87
|
+
if (result.error || result.status !== 0) {
|
|
88
|
+
throw new Error(`lizard failed: ${result.error?.message || result.stderr?.trim() || `exit ${result.status}`}`)
|
|
89
|
+
}
|
|
90
|
+
functions.push(...parseLizardCsv(result.stdout).map((fn) => ({ ...fn, file: relative(fn.file) })))
|
|
91
|
+
}
|
|
92
|
+
return functions
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Same-named functions in one file are told apart by their order of appearance.
|
|
97
|
+
function keyed(functions) {
|
|
98
|
+
const seen = new Map()
|
|
99
|
+
return functions.map((fn) => {
|
|
100
|
+
const base = `${fn.file}\0${fn.function}`
|
|
101
|
+
const count = seen.get(base) || 0
|
|
102
|
+
seen.set(base, count + 1)
|
|
103
|
+
return { key: `${base}\0${count}`, fn }
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function complexityDelta(before, after, { limit = 20 } = {}) {
|
|
108
|
+
const previous = new Map(keyed(before).map(({ key, fn }) => [key, fn.ccn]))
|
|
109
|
+
const rows = keyed(after).map(({ key, fn }) => ({
|
|
110
|
+
path: fn.file,
|
|
111
|
+
function: fn.function,
|
|
112
|
+
line: fn.line,
|
|
113
|
+
before: previous.has(key) ? previous.get(key) : null,
|
|
114
|
+
after: fn.ccn
|
|
115
|
+
}))
|
|
116
|
+
const increased = rows.filter((row) => row.before !== null && row.after > row.before)
|
|
117
|
+
const added = rows.filter((row) => row.before === null)
|
|
118
|
+
const afterKeys = new Set(keyed(after).map(({ key }) => key))
|
|
119
|
+
const decreased = rows.filter((row) => row.before !== null && row.after < row.before).length +
|
|
120
|
+
[...previous.keys()].filter((key) => !afterKeys.has(key)).length
|
|
121
|
+
const functions = [...increased, ...added.filter((row) => row.after > 1)]
|
|
122
|
+
.sort((left, right) => right.after - left.after || (right.after - (right.before ?? 1)) - (left.after - (left.before ?? 1)))
|
|
123
|
+
return {
|
|
124
|
+
increased: increased.length,
|
|
125
|
+
added: added.length,
|
|
126
|
+
decreased,
|
|
127
|
+
maxAfter: rows.reduce((max, row) => Math.max(max, row.after), 0),
|
|
128
|
+
functions: functions.slice(0, limit),
|
|
129
|
+
omitted: Math.max(0, functions.length - limit)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function withTemporaryFiles(files, callback) {
|
|
134
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-analyzer-'))
|
|
135
|
+
try {
|
|
136
|
+
for (const [relativePath, content] of files) {
|
|
137
|
+
const target = path.join(root, ...relativePath.split('/'))
|
|
138
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
139
|
+
fs.writeFileSync(target, content)
|
|
140
|
+
}
|
|
141
|
+
return callback(root)
|
|
142
|
+
} finally {
|
|
143
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import test from 'node:test'
|
|
7
|
+
import { complexityDelta, findLizard, lizardFunctions, parseLizardCsv } from './analyzers.mjs'
|
|
8
|
+
import { begin, check, hook } from './quality-delta.mjs'
|
|
9
|
+
|
|
10
|
+
const options = { detect: () => ({}) }
|
|
11
|
+
|
|
12
|
+
// Deterministic stand-in for lizard: one function per file, complexity 1 + number of `if`.
|
|
13
|
+
function fakeAnalyzer(cwd, files) {
|
|
14
|
+
return files.map((file) => ({
|
|
15
|
+
file,
|
|
16
|
+
function: 'main',
|
|
17
|
+
line: 1,
|
|
18
|
+
ccn: 1 + (fs.readFileSync(path.join(cwd, file), 'utf8').match(/\bif\b/g) || []).length,
|
|
19
|
+
nloc: 1
|
|
20
|
+
}))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function repository(t, policy) {
|
|
24
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-analyzers-'))
|
|
25
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }))
|
|
26
|
+
const git = (...args) => execFileSync('git', ['-C', root, ...args], { encoding: 'utf8' })
|
|
27
|
+
git('init', '-q')
|
|
28
|
+
git('config', 'user.email', 'analyzers@example.invalid')
|
|
29
|
+
git('config', 'user.name', 'Analyzer Test')
|
|
30
|
+
fs.mkdirSync(path.join(root, 'src'))
|
|
31
|
+
fs.writeFileSync(path.join(root, 'src', 'legacy.js'), 'export function main(a) {\n return a\n}\n')
|
|
32
|
+
if (policy) {
|
|
33
|
+
fs.mkdirSync(path.join(root, '.agent-os'))
|
|
34
|
+
fs.writeFileSync(path.join(root, '.agent-os', 'quality.json'), JSON.stringify({ schema: 1, checks: [], ...policy }))
|
|
35
|
+
}
|
|
36
|
+
git('add', '.')
|
|
37
|
+
git('commit', '-qm', 'fixture')
|
|
38
|
+
return root
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ifs = (count) => `export function main(a) {\n${' if (a) a++\n'.repeat(count)} return a\n}\n`
|
|
42
|
+
|
|
43
|
+
test('parses lizard CSV including quoted long names with commas', () => {
|
|
44
|
+
const functions = parseLizardCsv([
|
|
45
|
+
'6,2,17,2,6,"one@1-6@src/e.js","src/e.js","one","one ( a , b )",1,6',
|
|
46
|
+
'9,6,36,2,9,"branchy@1-9@src\\d.py","src\\d.py","branchy","branchy( a , b )",1,9',
|
|
47
|
+
'not,a,row'
|
|
48
|
+
].join('\r\n'))
|
|
49
|
+
assert.deepEqual(functions, [
|
|
50
|
+
{ file: 'src/e.js', function: 'one', line: 1, ccn: 2, nloc: 6 },
|
|
51
|
+
{ file: 'src/d.py', function: 'branchy', line: 1, ccn: 6, nloc: 9 }
|
|
52
|
+
])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('complexity delta ranks increased and new functions and counts reductions', () => {
|
|
56
|
+
const fn = (file, name, ccn) => ({ file, function: name, line: 1, ccn, nloc: 1 })
|
|
57
|
+
const delta = complexityDelta(
|
|
58
|
+
[fn('a.js', 'same', 3), fn('a.js', 'grew', 2), fn('a.js', 'shrank', 9), fn('a.js', 'gone', 4)],
|
|
59
|
+
[fn('a.js', 'same', 3), fn('a.js', 'grew', 7), fn('a.js', 'shrank', 5), fn('a.js', 'fresh', 12), fn('a.js', 'trivial', 1)]
|
|
60
|
+
)
|
|
61
|
+
assert.deepEqual(delta.functions.map((row) => [row.function, row.before, row.after]), [
|
|
62
|
+
['fresh', null, 12],
|
|
63
|
+
['grew', 2, 7]
|
|
64
|
+
])
|
|
65
|
+
assert.equal(delta.increased, 1)
|
|
66
|
+
assert.equal(delta.added, 2)
|
|
67
|
+
assert.equal(delta.decreased, 2)
|
|
68
|
+
assert.equal(delta.maxAfter, 12)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('check reports complexity deltas against clean entry content', (t) => {
|
|
72
|
+
const root = repository(t)
|
|
73
|
+
begin(root, options)
|
|
74
|
+
fs.writeFileSync(path.join(root, 'src', 'legacy.js'), ifs(3))
|
|
75
|
+
fs.writeFileSync(path.join(root, 'src', 'new.js'), ifs(5))
|
|
76
|
+
const evidence = check(root, { ...options, analyzeComplexity: fakeAnalyzer })
|
|
77
|
+
assert.equal(evidence.complexity.status, 'available')
|
|
78
|
+
assert.deepEqual(evidence.complexity.functions.map((row) => [row.path, row.before, row.after]), [
|
|
79
|
+
['src/new.js', null, 6],
|
|
80
|
+
['src/legacy.js', 1, 4]
|
|
81
|
+
])
|
|
82
|
+
assert.deepEqual(evidence.complexity.beforeUnavailable, [])
|
|
83
|
+
assert.equal(evidence.status, 'ok')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('a file dirty at begin has no recoverable before state', (t) => {
|
|
87
|
+
const root = repository(t)
|
|
88
|
+
fs.writeFileSync(path.join(root, 'src', 'legacy.js'), ifs(1))
|
|
89
|
+
begin(root, options)
|
|
90
|
+
fs.writeFileSync(path.join(root, 'src', 'legacy.js'), ifs(4))
|
|
91
|
+
const evidence = check(root, { ...options, analyzeComplexity: fakeAnalyzer })
|
|
92
|
+
assert.deepEqual(evidence.complexity.beforeUnavailable, ['src/legacy.js'])
|
|
93
|
+
assert.deepEqual(evidence.complexity.functions, [])
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('missing lizard is reported as unavailable without blocking', (t) => {
|
|
97
|
+
const root = repository(t)
|
|
98
|
+
begin(root, options)
|
|
99
|
+
fs.writeFileSync(path.join(root, 'src', 'legacy.js'), ifs(2))
|
|
100
|
+
const evidence = check(root, { ...options, analyzeComplexity: () => null })
|
|
101
|
+
assert.equal(evidence.complexity.status, 'unavailable')
|
|
102
|
+
assert.equal(evidence.status, 'ok')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('a project complexity threshold is advisory unless selected in blockSignals', (t) => {
|
|
106
|
+
const advisory = repository(t, { complexity: { threshold: 3 } })
|
|
107
|
+
begin(advisory, options)
|
|
108
|
+
fs.writeFileSync(path.join(advisory, 'src', 'legacy.js'), ifs(4))
|
|
109
|
+
const advised = check(advisory, { ...options, analyzeComplexity: fakeAnalyzer })
|
|
110
|
+
assert.equal(advised.status, 'ok')
|
|
111
|
+
assert.equal(advised.controls.signals[0].rule, 'complexity')
|
|
112
|
+
assert.equal(advised.controls.signals[0].required, false)
|
|
113
|
+
|
|
114
|
+
const blocking = repository(t, { complexity: { threshold: 3 }, blockSignals: ['complexity'] })
|
|
115
|
+
begin(blocking, options)
|
|
116
|
+
fs.writeFileSync(path.join(blocking, 'src', 'legacy.js'), ifs(4))
|
|
117
|
+
assert.equal(check(blocking, { ...options, analyzeComplexity: fakeAnalyzer }).status, 'blocked')
|
|
118
|
+
assert.match(hook(blocking).reason, /src\/legacy.js:1 complexity/)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('the complexity block rule requires a threshold', (t) => {
|
|
122
|
+
const root = repository(t, { blockSignals: ['complexity'] })
|
|
123
|
+
assert.throws(() => begin(root, options), /requires complexity.threshold/)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('real lizard output feeds the same delta', { skip: !findLizard() && 'lizard is not installed' }, (t) => {
|
|
127
|
+
const root = repository(t)
|
|
128
|
+
fs.writeFileSync(path.join(root, 'src', 'two.js'), 'function two(a) {\n if (a > 1) {\n return 1\n }\n return 0\n}\n')
|
|
129
|
+
const functions = lizardFunctions(root, ['src/two.js'])
|
|
130
|
+
assert.deepEqual(functions.map((fn) => [fn.file, fn.function, fn.ccn]), [['src/two.js', 'two', 2]])
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const python = ['python3', 'python'].find((name) => {
|
|
134
|
+
try {
|
|
135
|
+
return spawnSync(name, ['--version'], { encoding: 'utf8' }).status === 0
|
|
136
|
+
} catch {
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('a lizard.py in the repository never runs through python -m lizard', { skip: !python && 'python is not installed' }, (t) => {
|
|
142
|
+
const root = repository(t)
|
|
143
|
+
const marker = path.join(root, 'lizard-ran')
|
|
144
|
+
fs.writeFileSync(path.join(root, 'lizard.py'), `open(${JSON.stringify(marker)}, 'w').write('ran')\nprint('lizard 0.0.0')\n`)
|
|
145
|
+
const previous = process.cwd()
|
|
146
|
+
process.chdir(root)
|
|
147
|
+
try {
|
|
148
|
+
findLizard()
|
|
149
|
+
try {
|
|
150
|
+
lizardFunctions(root, ['src/legacy.js'], { launcher: [python, '-m', 'lizard'] })
|
|
151
|
+
} catch {
|
|
152
|
+
// Without a real lizard module the run fails; it must not import the repository's file.
|
|
153
|
+
}
|
|
154
|
+
} finally {
|
|
155
|
+
process.chdir(previous)
|
|
156
|
+
}
|
|
157
|
+
assert.equal(fs.existsSync(marker), false)
|
|
158
|
+
})
|