Skip to content

ci(lint): move static checks into lint, cut rule-harness time 75% - #1630

Merged
SaulMoro merged 22 commits into
Tencent:mainfrom
hz89Dev:feat/issue-1590-oxlint-rules
Oct 31, 2026
Merged

SaulMoro merged 22 commits into
Tencent:mainfrom
hz89Dev:feat/issue-1590-oxlint-rules

Conversation

@hz89Dev

@hz89Dev hz89Dev commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Static checks (import boundaries, banned APIs, required helper calls, doc drift) ran as Vitest tests that read src/ from disk, and the rule harness started one oxlint process per case. This moves them into npm run lint as enabled teamai/* rules plus a docs check/write script, deletes the scanners they replace, and batches ruleHarness into one oxlint per test file: the 105 rule tests run 75% faster (3.37 s → 0.85 s).

 npm run lint
   oxlint --type-aware ...        # loads oxlint-plugin-teamai
+    teamai/learnings-root          (now enabled; was registered only)
+    teamai/configured-tool-paths   teamai/launch-env
+    teamai/workflow-boundaries     teamai/no-provider-merge
+    teamai/windows-tests           teamai/rules-locate
+    teamai/workflow-failure-codes  teamai/config-load-options
+  node scripts/check-docs.mjs     # check mode; --write regenerates
+    commands.md, tool-support.md (en + zh-CN), README matrix,
+    skill commands exist, wiki codebase skill, workflow doc examples

 npx vitest run
-  workflow-module-boundaries.test.ts  (web-tree-sitter over all of src/, 60 s timeout)
-  learnings-path-guard / no-provider-merge / commands-reference / tool-support /
-  readme-matrix / skill-commands-exist / team-wiki-codebase-skill / workflow-docs-examples
-  source-scan blocks in home / launch-context / locate / rules / workflow-records / windows-test-list
   oxlint-plugin-teamai/rules/*.test.ts
-    ruleHarness: 1 oxlint process per case
+    ruleHarness: 1 oxlint process per file, diagnostics matched to each fixture and rule
 src/commands-reference.ts  ->  scripts/commands-reference.ts   # the CLI never imported them
 src/tool-support.ts        ->  scripts/tool-support.ts
-npx vitest run commands-reference -u
-npx vitest run tool-support -u
+node scripts/check-docs.mjs --write

What a contributor now sees (real output):

src/sync-cache.ts:3:35: error teamai(home-env): Read the user home through getUserHome() in src/utils/home.ts so USERPROFILE and platform fallbacks remain supported.
src/providers/github/auto-merge.ts:4:29: error teamai(no-provider-merge): Providers and workflow delivery must not merge, accept or enable auto-merge on pull requests.
src/workflow/drivers/skill/report.ts:1:1: error teamai(workflow-boundaries): Workflow module boundary forbids src/workflow/drivers/skill/report.ts -> src/workflow/engine.ts. Use the declared entry module or an explained inline disable.

Custom // learnings-root ok: comments and hardcoded allowlists became // oxlint-disable-next-line teamai/<rule> -- <reason>, which --report-unused-disable-directives keeps honest. AGENTS.md and .github/CONTRIBUTING.md say where these checks belong, replace the -u commands, and show each guard's failure and fix.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes (npm run typecheck, which also checks the plugin)
  • npm run lint passes (oxlint + Documentation checks passed.), on Node 24 and Node 22; Node 20 is left to CI
  • npx vitest run passes except three GitLab request-deadline tests that also fail on origin/main on this machine (below)
  • Added/updated tests for the change: one ruleHarness file per rule, written red first; scripts/check-docs.test.ts proves check mode never writes, stale output fails, and --write touches only the three generated files

Harness A/B: all 105 rule tests, same fixtures and rules; the only difference is one oxlint per case versus one per file. Five alternating runs, 105/105 passing every run.

Harness Median npx vitest run oxlint-plugin-teamai Range
one oxlint per case (before) 3.369 s 3.336–3.372 s
one oxlint per file (after) 0.850 s 0.848–0.855 s

Whole suite, for honesty: three alternating runs of npm run lint then npx vitest run on origin/main vs this branch. npx vitest run wall time is unchanged within noise (median 251.4 s → 253.7 s): it is dominated by Vitest worker setup across ~630 files, and this PR removes scanner files while adding the rule test files. npm run lint grows from ~1.8 s to ~5.5 s because it now runs the moved checks. The win is that violations fail in lint, before npm run build, and the rule suite no longer scales with one process per case.

Real CLI, after npm run build, the two E2E files covering the guarded helpers (removeDelivered, --dry-run refusal):

npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/dry-run-refusal.test.ts src/__tests__/e2e/remove-delivered-record-1577.test.ts
 Test Files  2 passed (2)
      Tests  17 passed (17)

Pre-existing failures, not touched here: gitlab-mr-create-timeout, gitlab-mr-timeout, gitlab-org-timeout fail on this host in isolation on both this branch and origin/main (78b6869c), so they are timing-sensitive on this machine, not caused by this diff.

Related Issues

Closes #1590

Notes for Reviewers

  • teamai/workflow-boundaries and the snapshot part of teamai/no-provider-merge follow transitive imports. oxlint's context.languageOptions.parser.parse throws not implemented yet, so the shared imports.js parses reachable dependencies with @babel/parser (pinned to the version already in the lockfile, now declared as a direct devDependency). The snapshot graph follows eager runtime imports only, matching the old scanner; the skill-driver graph also follows type, dynamic and vi.mock edges.
  • Rules fail closed. teamai/windows-tests throws if WINDOWS_TESTS has no literal list; teamai/rules-locate and the delivery scope of teamai/no-provider-merge throw Lint rule scope file missing: … if their file is renamed (checked by renaming src/resources/rules.ts: oxlint exits 1).
  • Source rules decide "production src/" from the package root (inProductionSource in utils.js), not from any /src/ in the absolute path. Before that, a checkout cloned under a directory named src (for example ~/src/teamai-cli) failed npm run lint on a clean tree with three teamai(launch-env) errors in the plugin's own file; it now exits 0 there and still reports src/ violations.
  • teamai/config-load-options checks that named loader calls pass preview options; it cannot prove the flag's value is forwarded ({ dryRun: false } passes). Every --dry-run preview case in dry-run-load-path.test.ts stays, checking that config.yaml is left unchanged. No E2E case is removed: the exclusion path in remove-delivered-record-1577.test.ts and the digest / import refusals in dry-run-refusal.test.ts prove behaviour the rules cannot.
  • Open PRs ci(lint): guard workflow providers against merging requests #1602, ci(lint): guard duplicate launch environment names #1607, ci(lint): guard POSIX-only Windows test fixtures #1608, ci(lint): guard workflow module boundaries #1609 and ci(lint): guard configured tool path joins #1611 each cover one slice of [feat] Move static checks from Vitest and E2E to oxlint-plugin-teamai and lint scripts #1590; this PR covers all of them with the scanners deleted in the same change, as the triage comment on the issue asks.
  • AGENTS.md exempts only docs-only, tests-only and lint-rule-only changes (no runtime code touched) from the real-CLI record.
  • Merge risk: two-way door. No CLI runtime behaviour changes: production src/ diffs are disable-comment swaps and the two generator files moving to scripts/. If a rule turns out too strict, a reasoned inline disable or a rule tweak fixes it.

Preserve per-fixture diagnostics while avoiding one subprocess per case. Verified all existing rule cases and typecheck.
Use standard explained disables and retain the canonical owner exemption. Preserve HOME and learnings runtime tests. Verified focused rules, home behavior, lint and typecheck.
Enforce path ownership for skills, rules and claudemd while retaining locate behavior coverage. Verified ruleHarness cases, locate tests, lint and typecheck.
Replace the source scan with an enabled rule while preserving launch runtime coverage. Verified 35 focused tests, lint and typecheck.
Preserve direct and transitive policies, standardize explained exceptions and retain the lookup type contract. Replace both source scanners. Verified rule fixtures, provider behavior, lint and typecheck.
Read the Windows CI selection from its existing owner and replace the POSIX source scan. Verified rule fixtures, list integrity, lint and typecheck.
Replace source inspection with a rule and retain OpenCode activation behavior tests. Verified focused tests, lint and typecheck.
Move producer enumeration out of Vitest while preserving record privacy and publication behavior. Verified 86 focused tests, lint and typecheck.
Move markdown consistency and executable guide checks into the lint command. Keep package and runtime skill coverage in Vitest.

Verified check/write CLI refusal cases, 152 focused tests, lint, typecheck, and check mode on Node 20.19.5.
Reject bare config-loader calls and object options that omit preview policy. Keep explained write and session paths local, and retain tests for wrapper behavior the rule cannot prove.

Verified red-green ruleHarness cases, 107 focused helper and runtime tests, lint, and typecheck.
Check deletion and ledger cleanup directly, including absent copies and neighboring paths. Keep tombstone and persisted uninstall coverage in the real CLI suite.

Verified focused helper tests and all six retained delivery E2Es after npm run build.
Use typed Babel traversal and separate import recognition from graph reachability. Keep policy array lookup tied to its runtime declarations.

Verified 95 rule cases, lint, typecheck, and subprocess coverage. Added characterization of re-exports, transitive mocks, TSX, and unrelated calls.
Keep the shared refusal unit cases and a real CLI profile-preservation case, plus init/provider ordering and Git preview transitions. Drop repeated classification-only CLI cases and the directly guarded projects loader row.

Verified 104 focused unit tests and 13 real CLI E2Es after npm run build.
@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] Preserve concatenated learnings-root detection — oxlint-plugin-teamai/rules/learnings-root.js:26. The deleted scanner rejected getKnowledgeDir(config) + '/learnings', but the replacement only checks path.join/path.resolve calls and interpolated templates. Concatenated roots now escape the accessor guard. Add an equivalent AST check and regression fixture before dropping that coverage.

The PR description documents sufficient testing: it records a post-build real-CLI E2E run with 2 files and 13 tests passing. No testing-record blocker.

Review was read-only; I did not run, build, or install PR code.

@hz89Dev

hz89Dev commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed in e545ed2. teamai/learnings-root now reports any '/learnings' literal and any template ending in /learnings, matching the deleted scanner's ['"`]\/learnings['"`] pattern. That covers getKnowledgeDir(config) + '/learnings' and `/learnings`, and each case went red before the change. npm run lint over the repo stays clean, so no existing call site depended on the gap.

@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] Normalize the delivery path in the snapshot guard — oxlint-plugin-teamai/rules/workflow-boundaries.js:96. sourceImport() returns native Windows paths, but the delivery check uses an unnormalized file.endsWith('/src/workflow/pr-delivery.ts'). A snapshot dependency reaching delivery without also reaching a provider escapes detection; the added “rejects snapshot loading delivery through a re-export” fixture consequently fails on Windows. Normalize the path for both checks.

Earlier concatenated-learnings-root finding: resolved by the new /learnings literal visitor and regression fixture.

The PR description documents sufficient testing, including a post-build real-CLI E2E record: 2 files, 13 tests passed. No testing-record blocker.

Review was read-only; I did not run, build, or install PR code.

@hz89Dev

hz89Dev commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 409eacc. The snapshot predicate now converts the path reachesSource() returns to / separators once, and uses the result for both the /src/providers/ and /src/workflow/pr-delivery.ts checks. Previously only the providers check was normalized. I checked this on macOS only: the 107 rule tests and npm run lint pass there. The Windows CI job doesn't run the plugin tests, so the backslash case still hasn't been exercised on a real Windows run.

@github-actions

Copy link
Copy Markdown
  • [P2 non-blocking] Retain behavioral dry-run forwarding tests — src/__tests__/dry-run-load-path.test.ts:343. The removed cases for commands such as mcp inject and source add verify that previews actually leave legacy configuration unchanged; they are not source scanners. The replacement rule accepts { dryRun: false } and arbitrary options identifiers, so it cannot detect broken flag forwarding. Retain these behavioral cases alongside the lint rule.

Both earlier findings are resolved: concatenated learnings roots are detected, and the snapshot delivery check normalizes Windows paths.

The PR description documents sufficient testing, including a post-build real-CLI run with 2 files and 13 tests passing. No testing-record blocker.

Review was read-only; I did not run, build, or install PR code.

@hz89Dev

hz89Dev commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, they test behaviour, not source. Restored in 9c37bac: dry-run-load-path.test.ts is back to its main version (97 tests pass), so every preview case, mcp inject, source add and import included, still checks that config.yaml is unchanged under --dry-run. teamai/config-load-options only adds the static check that named loader calls pass preview options. The PR body now says the rule cannot prove the forwarded value.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Re-checked at 409eacc9 (reviewed at 2bfef910, then the two follow-ups). This does what #1590 asked: the scanners are gone, every teamai/* rule is enabled (including learnings-root), the doc generators moved to scripts/ and check-docs.mjs runs in npm run lint, and the built dist/index.js is byte-identical to main. @babel/parser and @babel/types add nothing to the lockfile; they were already installed at the same version through @vitest/coverage-v8.

The automated review's point is fixed in e545ed2f: getKnowledgeDir(config) + '/learnings', a bare '/learnings' literal and an expression-less template are all reported now (probed). The new test covers the first two; a fixture for the bare literal would pin the third.

[P1 blocking] The dry-run cases removed from dry-run-load-path.test.ts are not replaced. remove, roles init/add/remove/update, source add/remove/add-http, packages install, import --from-iwiki/--from-mr/--from-claude and mcp inject lost their runtime check that config.yaml is not rewritten under --dry-run. teamai/config-load-options only checks that a dryRun property is present, not that it carries the flag: changing src/remove.ts to pass { dryRun: false } still passes lint, and the built CLI then migrates config.yaml under teamai remove … --dry-run, while the unmodified build leaves it untouched. The new comment ("These wrapper paths are not proven by the direct config-load rule") says the same. Restoring those rows in the existing it.each table keeps the runtime guarantee; the lint rule can stay as the cheap first line.

Non-blocking:

  • [P2 non-blocking] Two E2E cases go without a replacement: "pull deletes a skill the member excludes and takes it off the record" in remove-delivered-record-1577.test.ts (the rule proves the helper is called, not the exclusion path), and the digest / import --dry-run refusal in dry-run-refusal.test.ts (dry-run-guard only checks the classification).
  • [P2 non-blocking] AGENTS.md now exempts "a docs-only, tests-only, or static guard change" from the real-CLI record. "Static guard" also covers a PR that changes runtime code alongside a rule; #1590 asked only that lint-enforced helper calls need npm run lint plus the helper's unit test. Scoping it to "no runtime change" keeps the rule as asked.
  • [P3 nit] workflow-records.test.ts also failed when a code in KNOWN_FAILURE_CODES was never written; the rule checks only the forward direction, so dead entries pass.
  • [P3 nit] no-provider-merge.js scopes with file.includes('/src/providers/'), the substring approach 8875e595 removed from the other rules.
  • [P3 nit] Stale comments after the move: src/tools.ts:311 names tool-support.ts (now under scripts/), and .github/workflows/ci.yml:237 says windows-test-list.test.ts keeps the list honest (now teamai/windows-tests).

@hz89Dev

hz89Dev commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

All points addressed at df177ad.

  • [P1] dry-run-load-path.test.ts is back to its main version (9c37bac), so every preview row (remove, roles *, source *, packages install, import *, mcp inject) checks again that config.yaml is unchanged under --dry-run. teamai/config-load-options stays as the static first line. 97 tests pass.
  • [P2] Both E2E files are restored in full (00eb5ee): the exclusion path in remove-delivered-record-1577.test.ts, and the digest / import refusals in dry-run-refusal.test.ts. 17 tests pass against the built CLI.
  • [P2] AGENTS.md now exempts only "docs-only, tests-only, or lint-rule-only (no runtime code touched)" changes, in both ## Testing before a PR and ## Code Review Rules. CONTRIBUTING.md matches (df177ad).
  • [P3] teamai/no-provider-merge now scopes with sourcePath(), the package-root path the other rules use. A red fixture shows src/providers/teamai-cli/scripts/release.ts no longer counts as provider code (66b8821).
  • [P3] Bare '/learnings' literal fixture added.
  • [P3] Stale comments fixed: src/tools.ts now names scripts/tool-support.ts, and ci.yml names both windows-test-list.test.ts (entries exist) and teamai/windows-tests (no POSIX-only code).
  • [P3] Unused KNOWN_FAILURE_CODES entries: not added. An oxlint rule sees one file at a time, so the reverse direction needs a pass over all of src/, which brings back the source scan [feat] Move static checks from Vitest and E2E to oxlint-plugin-teamai and lint scripts #1590 removes. A stale entry only widens what is accepted as classified; it never lets an unclassified code through. If you want it anyway, it fits as one check in the scripts/ runner that npm run lint already calls.

@github-actions

Copy link
Copy Markdown

No new findings in the scoped PR diff.

All three earlier findings are resolved:

  • Concatenated learnings roots are detected.
  • Snapshot delivery checks normalize Windows paths.
  • Behavioral dry-run forwarding tests remain intact.

The PR description documents sufficient testing: a post-build real-CLI E2E run records 2 files and 17 tests passing. No testing-record blocker.

Review was read-only; I did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI during triage.

Approved at df177ad1. dry-run-load-path.test.ts is back to main's version, so every --dry-run command still checks at runtime that config.yaml is not rewritten. The two E2E cases are restored (excluded-skill pull, and the digest / import preview refusal), the AGENTS.md exemption is scoped to lint-rule-only changes with no runtime code, no-provider-merge scopes from the package root with a test for a parent src/providers/ directory, the bare '/learnings' literal has a fixture, and the stale comments are updated (the ci.yml change is comment-only). Remaining from my earlier notes, non-blocking: the reverse check that every KNOWN_FAILURE_CODES entry is still written. The automated review at this head reports no new findings and marks its earlier three resolved. CI is green.

@SaulMoro
SaulMoro merged commit 9f1b453 into Tencent:main Oct 31, 2026
18 checks passed
SaulMoro added a commit to SaulMoro/teamai-cli that referenced this pull request Oct 31, 2026
Main moved the static checks from Vitest scanners into lint (Tencent#1630). The
benchmark additions to the deleted scanners move with them: the
src/benchmark/ entries and the rule that no workflow module imports a
benchmark module go to teamai/workflow-boundaries, the benchmark refusal
codes to the failure-code policy, the README benchmarks column to
doc-checks/readme-matrix, and the benchmark guide checks to
doc-checks/workflow-docs-examples.
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
…t#1630)

Move the static checks that ran as Vitest scanners (import boundaries,
banned APIs, required helper calls, doc drift) into npm run lint: enabled
teamai/* rules plus scripts/check-docs.mjs, whose --write mode regenerates
the command reference and tool-support pages. Delete the scanners they
replace, batch ruleHarness into one oxlint run per test file, and update
AGENTS.md and CONTRIBUTING.md.

Closes Tencent#1590.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Move static checks from Vitest and E2E to oxlint-plugin-teamai and lint scripts

3 participants