@milkenjoyer/toolchain 0.21.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +2 -0
  2. package/TESTING.md +26 -0
  3. package/dist/{effect-plugin-BiskbKO9.mjs → effect-plugin-roghk4W1.mjs} +0 -1
  4. package/dist/effect-plugin.mjs +1 -1
  5. package/dist/exceptions-D0yZUk8P.mjs +145 -0
  6. package/dist/exceptions.mjs +1 -1
  7. package/dist/{guard-CAm90ZGy.mjs → guard-n0LC_buo.mjs} +2 -2
  8. package/dist/guard.mjs +1 -1
  9. package/dist/{lint-CiO5Etue.mjs → lint-Bx4NP_kA.mjs} +4 -4
  10. package/dist/lint.mjs +1 -1
  11. package/dist/{plugin-DwQM07Ih.mjs → plugin-DUUAfi92.mjs} +324 -28
  12. package/dist/plugin.d.mts +5 -0
  13. package/dist/plugin.mjs +1 -1
  14. package/dist/{renovate-ci-BdVmECgm.mjs → renovate-ci-_6NQAucj.mjs} +7 -3
  15. package/dist/renovate-ci.d.mts +2 -1
  16. package/dist/renovate-ci.mjs +1 -1
  17. package/dist/{rules-vHmNoAU0.mjs → rules-5qwzfDWJ.mjs} +3 -1
  18. package/dist/rules.d.mts +2 -0
  19. package/dist/rules.mjs +1 -1
  20. package/dist/standard.mjs +1 -1
  21. package/dist/starts.mjs +1 -1
  22. package/package.json +2 -1
  23. package/src/effect-plugin.ts +0 -1
  24. package/src/exceptions.ts +132 -0
  25. package/src/plugin.ts +10 -0
  26. package/src/renovate-ci.ts +5 -2
  27. package/src/rules/no-mock-call-mirrors.ts +121 -0
  28. package/src/rules/no-test-internal-imports.ts +102 -0
  29. package/src/rules/no-test-timeouts.ts +83 -0
  30. package/src/rules/no-test-waits.ts +113 -0
  31. package/src/rules/require-test-quarantine.ts +36 -0
  32. package/src/rules/test-api.ts +57 -0
  33. package/src/rules/test-hygiene.test.ts +241 -0
  34. package/src/rules/test-package.ts +32 -0
  35. package/src/rules.ts +2 -0
  36. package/src/shared/member-path.ts +7 -0
  37. package/dist/exceptions-Dybl9xpc.mjs +0 -11
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ Test hygiene rules and quarantine syntax: [TESTING.md](TESTING.md).
2
+
1
3
  # Configure pre-push hooks
2
4
 
3
5
  A shared absolute Git hooks path must dispatch through the invoking worktree. `@milkenjoyer/toolchain/hooks` supplies `configurePrePush` to run native Vite+ setup and install that dispatcher as one operation.
package/TESTING.md ADDED
@@ -0,0 +1,26 @@
1
+ # Test hygiene
2
+
3
+ Toolchain 0.22.0 enables these `birbprophet` rules at error in `lint()`. `guard` rejects lowering them outside the shared exact-file exceptions. They apply to `.test`, `.spec` and `.fake` TypeScript/JavaScript files and files inside `test`, `tests` or `__tests__` directories. Timeout/retry configuration is also checked in Vite and Vitest config files. The timeout rule also rejects `--retry` in the containing package's scripts.
4
+
5
+ | Rule | Required repair | Replaces |
6
+ | --- | --- | --- |
7
+ | `no-test-timeouts` | Remove per-test timeout arguments, timeout/retry options and `--retry`; fix the slow or flaky test. | Manual checks for timeout and retry overrides. |
8
+ | `no-test-waits` | Await observable completion or use a controlled test clock; remove sleeps, polling, wall-clock measurements and frame waits. | Manual checks for time-based synchronization. |
9
+ | `require-test-quarantine` | Restore the skipped test or name its repair issue immediately above the call. | The unconditional `vitest/no-disabled-tests` and `vitest/warn-todo` bans. |
10
+ | `no-mock-call-mirrors` | Run the local module and assert its observable result instead of its mocked call history. | The unconditional `effect/no-module-mocking` ban. |
11
+ | `no-test-internal-imports` | Use a package export or place the test beside its subject. | Manual checks for cross-directory internal imports. |
12
+
13
+ A quarantine uses a statement, preserving the no-comments rule:
14
+
15
+ ```ts
16
+ import { it } from "@effect/vitest";
17
+
18
+ void "quarantine: #532";
19
+ it.skip("repairs the affected behavior", () => {});
20
+ ```
21
+
22
+ The issue marker must be on the immediately preceding line. Empty, zero and missing issue numbers fail. Namespaced and renamed test imports are recognized. Correct cases retain normal runner defaults, event completion, controlled clocks, public exported subpaths and colocated internal imports. External SDK mocks remain allowed.
23
+
24
+ Existing agent-kit violations are listed by exact filename and rule in `exceptions.ts`, linked to #532. Remove each exception as that cleanup repairs its file. No directory-wide exemption is shipped.
25
+
26
+ Siglata, vibebattler and OptionHouse need `@milkenjoyer/toolchain` pinned to `0.22.0` or a later compatible release. Their `0.18`/`0.10` pins do not contain these rules. Update the dependency pin after publication; consume the package's preset rather than copying rule files. Siglata #3564 and OptionHouse #1142 own their ongoing ports. Each repo's cleanup campaign owns its existing violations.
@@ -64,7 +64,6 @@ const kept = [
64
64
  "avoid-mutable-state",
65
65
  "avoid-option-getorthrow",
66
66
  "no-chained-type-assertions",
67
- "no-module-mocking",
68
67
  "prefer-redacted-config",
69
68
  "require-effect-concurrency",
70
69
  "throw-in-effect-gen"
@@ -1 +1 @@
1
- export { t as default } from "./effect-plugin-BiskbKO9.mjs";
1
+ export { t as default } from "./effect-plugin-roghk4W1.mjs";
@@ -0,0 +1,145 @@
1
+ // src/exceptions.ts
2
+ const exceptions = [
3
+ {
4
+ files: [
5
+ "packages/toolchain/tests/renovate-ci.test.ts",
6
+ "packages/toolchain/tests/standard-fixture.ts",
7
+ "plugins/agent-kit/tests/board.test.ts",
8
+ "plugins/agent-kit/tests/codex-usage.test.ts",
9
+ "plugins/agent-kit/tests/kept-clock.test.ts",
10
+ "plugins/agent-kit/tests/kept-clock.ts",
11
+ "plugins/agent-kit/tests/kept-fake.ts",
12
+ "plugins/agent-kit/tests/kept-fixes.test.ts",
13
+ "plugins/agent-kit/tests/kept-plan.test.ts",
14
+ "plugins/agent-kit/tests/kept-relocation.test.ts",
15
+ "plugins/agent-kit/tests/kept-runner.test.ts",
16
+ "plugins/agent-kit/tests/kept.test.ts",
17
+ "plugins/agent-kit/tests/pool-quota.test.ts",
18
+ "plugins/agent-kit/tests/request-ready.test.ts",
19
+ "plugins/agent-kit/tests/wait-ready.test.ts",
20
+ "tests/ready-request.test.ts",
21
+ "tests/repo-guard/check.test.ts"
22
+ ],
23
+ rules: ["birbprophet/no-test-waits"],
24
+ issue: "https://github.com/birbprophet/agent-kit/issues/532"
25
+ },
26
+ {
27
+ files: [
28
+ "packages/toolchain/tests/bins-packed.test.ts",
29
+ "packages/toolchain/tests/build.test.ts",
30
+ "packages/toolchain/tests/false-positives.test.ts",
31
+ "packages/toolchain/tests/formal-arithmetic.test.ts",
32
+ "packages/toolchain/tests/formal-proofs.test.ts",
33
+ "packages/toolchain/tests/formal.test.ts",
34
+ "packages/toolchain/tests/hooks.test.ts",
35
+ "packages/toolchain/tests/knip.test.ts",
36
+ "packages/toolchain/tests/rules.test.ts",
37
+ "packages/toolchain/tests/standard-aggregate-ids.test.ts",
38
+ "packages/toolchain/tests/standard-config.test.ts",
39
+ "packages/toolchain/tests/standard-domain-layout.test.ts",
40
+ "packages/toolchain/tests/standard-domain.test.ts",
41
+ "packages/toolchain/tests/standard-infra.test.ts",
42
+ "packages/toolchain/tests/standard-pins.test.ts",
43
+ "packages/toolchain/tests/standard-rules.test.ts",
44
+ "plugins/agent-kit/tests/codex-launch.test.ts",
45
+ "plugins/agent-kit/tests/kept-admission.test.ts",
46
+ "plugins/agent-kit/tests/kept-fixes.test.ts",
47
+ "plugins/agent-kit/tests/kept-relocation.test.ts",
48
+ "plugins/agent-kit/tests/kept-runner.test.ts",
49
+ "plugins/agent-kit/tests/kept.test.ts",
50
+ "tests/no-comments.test.ts",
51
+ "tests/repo-guard/check.test.ts",
52
+ "tests/spawned-commands.test.ts"
53
+ ],
54
+ rules: ["birbprophet/no-test-timeouts"],
55
+ issue: "https://github.com/birbprophet/agent-kit/issues/532"
56
+ },
57
+ {
58
+ files: [
59
+ "packages/toolchain/tests/catalog.test.ts",
60
+ "packages/toolchain/tests/ci-budget.test.ts",
61
+ "packages/toolchain/tests/fixtures/formal/formal/counter.conformance.ts",
62
+ "packages/toolchain/tests/fixtures/proofs/formal/add32.proof.ts",
63
+ "packages/toolchain/tests/fixtures/proofs/formal/credits.proof.ts",
64
+ "packages/toolchain/tests/fixtures/proofs/formal/next-below.proof.ts",
65
+ "packages/toolchain/tests/fixtures/proofs/formal/used-percent.proof.ts",
66
+ "packages/toolchain/tests/foldkit-vite.test.ts",
67
+ "packages/toolchain/tests/formal-traces.test.ts",
68
+ "packages/toolchain/tests/hooks-fixture.ts",
69
+ "packages/toolchain/tests/hooks.test.ts",
70
+ "packages/toolchain/tests/renovate-ci.test.ts",
71
+ "packages/toolchain/tests/renovate.test.ts",
72
+ "packages/toolchain/tests/rules.test.ts",
73
+ "packages/toolchain/tests/rules/no-comments.test.ts",
74
+ "packages/toolchain/tests/rules/no-process-env.test.ts",
75
+ "packages/toolchain/tests/rules/prefer-accessible-scene-locators.test.ts",
76
+ "packages/toolchain/tests/rules/require-command-answer-names.test.ts",
77
+ "packages/toolchain/tests/rules/require-past-tense-messages.test.ts",
78
+ "packages/toolchain/tests/rules/use-temp-file-scoped.test.ts",
79
+ "packages/toolchain/tests/solver.test.ts",
80
+ "packages/toolchain/tests/standard-domain.test.ts",
81
+ "packages/toolchain/tests/standard-infra.test.ts",
82
+ "packages/toolchain/tests/standard-pins.test.ts",
83
+ "packages/toolchain/tests/standard.test.ts",
84
+ "packages/toolchain/tests/starts-policy.test.ts",
85
+ "packages/toolchain/tests/verdict.test.ts",
86
+ "packages/toolchain/tests/verification.test.ts",
87
+ "plugins/agent-kit/tests/board.test.ts",
88
+ "plugins/agent-kit/tests/boat-cost.test.ts",
89
+ "plugins/agent-kit/tests/boat-paid.test.ts",
90
+ "plugins/agent-kit/tests/cleanup.test.ts",
91
+ "plugins/agent-kit/tests/codex-launch.test.ts",
92
+ "plugins/agent-kit/tests/codex-usage.test.ts",
93
+ "plugins/agent-kit/tests/disk-policy.test.ts",
94
+ "plugins/agent-kit/tests/fixed-model-quota.test.ts",
95
+ "plugins/agent-kit/tests/free-resets.test.ts",
96
+ "plugins/agent-kit/tests/kept-admission.test.ts",
97
+ "plugins/agent-kit/tests/kept-cli.test.ts",
98
+ "plugins/agent-kit/tests/kept-clock.test.ts",
99
+ "plugins/agent-kit/tests/kept-fake.ts",
100
+ "plugins/agent-kit/tests/kept-fixes.test.ts",
101
+ "plugins/agent-kit/tests/kept-hydration.test.ts",
102
+ "plugins/agent-kit/tests/kept-observation.test.ts",
103
+ "plugins/agent-kit/tests/kept-plan.test.ts",
104
+ "plugins/agent-kit/tests/kept-relocation.test.ts",
105
+ "plugins/agent-kit/tests/kept-runner.test.ts",
106
+ "plugins/agent-kit/tests/kept.test.ts",
107
+ "plugins/agent-kit/tests/pool-order.test.ts",
108
+ "plugins/agent-kit/tests/pool-quota.test.ts",
109
+ "plugins/agent-kit/tests/provider-slots.test.ts",
110
+ "plugins/agent-kit/tests/proxy-quota.test.ts",
111
+ "plugins/agent-kit/tests/queue-fixture.ts",
112
+ "plugins/agent-kit/tests/queue-members.test.ts",
113
+ "plugins/agent-kit/tests/queue-plan.test.ts",
114
+ "plugins/agent-kit/tests/queue-resets.test.ts",
115
+ "plugins/agent-kit/tests/queue-unread.test.ts",
116
+ "plugins/agent-kit/tests/queue-upkeep.test.ts",
117
+ "plugins/agent-kit/tests/queue-usage.test.ts",
118
+ "plugins/agent-kit/tests/queue.test.ts",
119
+ "plugins/agent-kit/tests/request-ready.test.ts",
120
+ "plugins/agent-kit/tests/trust-hooks.test.ts",
121
+ "plugins/agent-kit/tests/unbound-census.test.ts",
122
+ "plugins/agent-kit/tests/wait-ready.test.ts",
123
+ "tests/exact-versions.test.ts",
124
+ "tests/ready-main.test.ts",
125
+ "tests/ready-request.test.ts",
126
+ "tests/spawned-commands.test.ts",
127
+ "tests/standard-plugin-skills.test.ts",
128
+ "tests/toolchain-adoption.test.ts",
129
+ "tests/workflow-policy.test.ts",
130
+ "tests/workflow-shell.test.ts"
131
+ ],
132
+ rules: ["birbprophet/no-test-internal-imports"],
133
+ issue: "https://github.com/birbprophet/agent-kit/issues/532"
134
+ },
135
+ {
136
+ files: ["packages/toolchain/src/conformance.ts"],
137
+ rules: [
138
+ "eslint/no-restricted-imports",
139
+ "vitest/no-disabled-tests",
140
+ "vitest/no-conditional-tests"
141
+ ],
142
+ issue: "https://github.com/birbprophet/agent-kit/issues/278"
143
+ }
144
+ ];
145
+ export { exceptions as t };
@@ -1 +1 @@
1
- export { t as exceptions } from "./exceptions-Dybl9xpc.mjs";
1
+ export { t as exceptions } from "./exceptions-D0yZUk8P.mjs";
@@ -1,7 +1,7 @@
1
1
  import { d as otherTags, l as latestOf, u as onLatestLine } from "./compatible-CRaMYpBM.mjs";
2
2
  import { i as enforcedTsgoRules } from "./effect-tsgo-D0QfeKGD.mjs";
3
- import { t as exceptions } from "./exceptions-Dybl9xpc.mjs";
4
- import { a as toolchainScopes, n as effectRules, r as foldkitPreset, t as birbprophetRules } from "./lint-CiO5Etue.mjs";
3
+ import { t as exceptions } from "./exceptions-D0yZUk8P.mjs";
4
+ import { a as toolchainScopes, n as effectRules, r as foldkitPreset, t as birbprophetRules } from "./lint-Bx4NP_kA.mjs";
5
5
  import { c as lead, f as versionOf } from "./versions-KbYa8kbF.mjs";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Schema from "effect/Schema";
package/dist/guard.mjs CHANGED
@@ -1 +1 @@
1
- export { c as exactFindings, t as exceptionFindings, n as foldkitViteFindings, r as isFoldkitViteInput, l as manifestRanges, i as pinFindings, a as ruleFindings, o as tagFindings } from "./guard-CAm90ZGy.mjs";
1
+ export { c as exactFindings, t as exceptionFindings, n as foldkitViteFindings, r as isFoldkitViteInput, l as manifestRanges, i as pinFindings, a as ruleFindings, o as tagFindings } from "./guard-n0LC_buo.mjs";
@@ -1,8 +1,8 @@
1
- import { t as plugin } from "./effect-plugin-BiskbKO9.mjs";
1
+ import { t as plugin } from "./effect-plugin-roghk4W1.mjs";
2
2
  import { n as effectTsgoPlugin, r as effectTsgoRules } from "./effect-tsgo-D0QfeKGD.mjs";
3
- import { t as exceptions } from "./exceptions-Dybl9xpc.mjs";
4
- import { t as plugin$1 } from "./plugin-DwQM07Ih.mjs";
5
- import { t as staticRules } from "./rules-vHmNoAU0.mjs";
3
+ import { t as exceptions } from "./exceptions-D0yZUk8P.mjs";
4
+ import { t as plugin$1 } from "./plugin-DUUAfi92.mjs";
5
+ import { t as staticRules } from "./rules-5qwzfDWJ.mjs";
6
6
  import * as Schema from "effect/Schema";
7
7
  import * as Arr from "effect/Array";
8
8
  import * as Option from "effect/Option";
package/dist/lint.mjs CHANGED
@@ -1 +1 @@
1
- export { t as birbprophetRules, n as effectRules, r as foldkitPreset, i as lint, a as toolchainScopes } from "./lint-CiO5Etue.mjs";
1
+ export { t as birbprophetRules, n as effectRules, r as foldkitPreset, i as lint, a as toolchainScopes } from "./lint-Bx4NP_kA.mjs";
@@ -1,11 +1,15 @@
1
1
  import { i as unwrapExpression, n as memberPropertyName, r as propertyName, t as isStringLiteral } from "./syntax-B3n7lDYJ.mjs";
2
+ import { createRequire } from "node:module";
2
3
  import * as Effect from "effect/Effect";
4
+ import * as Schema from "effect/Schema";
3
5
  import * as Arr from "effect/Array";
4
6
  import { dual } from "effect/Function";
5
7
  import * as HashSet from "effect/HashSet";
6
8
  import * as Option from "effect/Option";
7
9
  import * as Str from "effect/String";
10
+ import { existsSync, readFileSync } from "node:fs";
8
11
  import { Comment, Diagnostic, Plugin, Rule, RuleContext } from "effect-oxlint";
12
+ import { dirname, join, resolve } from "node:path";
9
13
  import * as HashMap from "effect/HashMap";
10
14
  // src/rules/no-comments.ts
11
15
  const noCommentsRule = Rule.define({
@@ -26,34 +30,6 @@ const noCommentsRule = Rule.define({
26
30
  }),
27
31
  name: "no-comments"
28
32
  });
29
- // src/rules/no-process-env.ts
30
- const passesEnvironment = (node) => {
31
- const parent = node.parent;
32
- return parent.type === "SpreadElement" || (parent.type === "CallExpression" || parent.type === "NewExpression") && parent.arguments.includes(node) || parent.type === "VariableDeclarator" && parent.init === node && parent.id.type === "ObjectPattern" && Arr.some(parent.id.properties, (property) => property.type === "RestElement");
33
- };
34
- const isGlobalProcess = (source, node) => {
35
- const lookup = (scope) => {
36
- const variable = scope.set.get(node.name);
37
- if (variable !== void 0 && variable.defs.length > 0) return false;
38
- return scope.upper === null ? true : lookup(scope.upper);
39
- };
40
- return lookup(source.getScope(node));
41
- };
42
- const noProcessEnvRule = Rule.define({
43
- name: "no-process-env",
44
- meta: Rule.meta({
45
- type: "suggestion",
46
- description: "Read configuration through Effect Config",
47
- messages: { config: "Read configuration through Effect Config. Passing the whole environment through is allowed." }
48
- }),
49
- *create() {
50
- const context = yield* RuleContext;
51
- return { MemberExpression: (node) => node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "process" && isGlobalProcess(context.sourceCode, node.object) && Option.contains(memberPropertyName(node), "env") && !passesEnvironment(node) ? context.report(Diagnostic.fromId({
52
- node,
53
- messageId: "config"
54
- })) : Effect.void };
55
- }
56
- });
57
33
  // src/shared/member-path.ts
58
34
  const resolveBinding = (sourceCode, node) => {
59
35
  const findBinding = (scope) => Option.flatMap(scope, (current) => Option.orElse(Option.fromUndefinedOr(current.set.get(node.name)), () => findBinding(Option.fromNullishOr(current.upper))));
@@ -83,6 +59,10 @@ const importedPath = dual(2, (sourceCode, node) => Option.gen(function* () {
83
59
  source: declaration.source.value,
84
60
  members: path.members
85
61
  };
62
+ if (specifier.type === "ImportDefaultSpecifier") return {
63
+ source: declaration.source.value,
64
+ members: ["default", ...path.members]
65
+ };
86
66
  if (specifier.type !== "ImportSpecifier") return yield* Option.none();
87
67
  const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
88
68
  return {
@@ -90,6 +70,289 @@ const importedPath = dual(2, (sourceCode, node) => Option.gen(function* () {
90
70
  members: [imported, ...path.members]
91
71
  };
92
72
  }));
73
+ // src/rules/test-api.ts
74
+ const isTestFile = (filename) => /(?:\.(?:test|spec|fake)\.[cm]?[jt]sx?$|\/(?:tests?|__tests__)\/)/u.test(filename);
75
+ const testPath = (source, node) => Option.match(importedPath(source, node), {
76
+ onNone: () => {
77
+ const names = source.getText(node).split(".");
78
+ return [
79
+ "it",
80
+ "test",
81
+ "describe",
82
+ "beforeEach",
83
+ "afterEach",
84
+ "beforeAll",
85
+ "afterAll",
86
+ "vi",
87
+ "vitest",
88
+ "expect"
89
+ ].includes(names[0] ?? "") ? names : [];
90
+ },
91
+ onSome: ({ source: module, members }) => [
92
+ "@effect/vitest",
93
+ "vitest",
94
+ "vite-plus/test",
95
+ "bun:test",
96
+ "node:test"
97
+ ].includes(module) ? members : []
98
+ });
99
+ const isTestCall = (source, node) => [
100
+ "it",
101
+ "test",
102
+ "describe",
103
+ "beforeEach",
104
+ "afterEach",
105
+ "beforeAll",
106
+ "afterAll"
107
+ ].includes(testPath(source, node)[0] ?? "");
108
+ // src/rules/test-package.ts
109
+ const Manifest = Schema.fromJsonString(Schema.Struct({
110
+ name: Schema.optionalKey(Schema.String),
111
+ scripts: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
112
+ exports: Schema.optionalKey(Schema.Unknown)
113
+ }));
114
+ const manifestAt = (folder) => {
115
+ const file = join(folder, "package.json");
116
+ if (!existsSync(file)) return Option.none();
117
+ return Schema.decodeOption(Manifest)(readFileSync(file, "utf8"));
118
+ };
119
+ const packageAt = (folder) => {
120
+ const manifest = manifestAt(folder);
121
+ if (Option.isSome(manifest)) return Option.some({
122
+ root: folder,
123
+ manifest: manifest.value
124
+ });
125
+ const parent = dirname(folder);
126
+ return parent === folder ? Option.none() : packageAt(parent);
127
+ };
128
+ // src/rules/no-mock-call-mirrors.ts
129
+ const noMockCallMirrorsRule = Rule.define({
130
+ *create() {
131
+ const context = yield* RuleContext;
132
+ if (!isTestFile(context.filename)) return {};
133
+ const own = packageAt(dirname(context.filename));
134
+ const require = createRequire(context.filename);
135
+ const local = (source) => {
136
+ if (/^(?:\.|#)/u.test(source) || Option.exists(own, ({ manifest }) => manifest.name !== void 0 && (source === manifest.name || source.startsWith(`${manifest.name}/`)))) return true;
137
+ try {
138
+ const resolved = require.resolve(source);
139
+ return resolved.startsWith("/") && !resolved.includes("/node_modules/");
140
+ } catch {
141
+ return false;
142
+ }
143
+ };
144
+ const mocked = /* @__PURE__ */ new Set();
145
+ const assertions = [];
146
+ const sourceOf = (node) => {
147
+ const value = unwrapExpression(node);
148
+ if (value.type === "CallExpression" && ["mocked", "expect"].includes(Option.getOrElse(lastName(value.callee), () => ""))) {
149
+ const [first] = value.arguments;
150
+ return first === void 0 ? Option.none() : sourceOf(first);
151
+ }
152
+ return Option.map(importedPath(context.sourceCode, value), ({ source }) => source);
153
+ };
154
+ return {
155
+ CallExpression: (node) => {
156
+ if (node.type !== "CallExpression") return Effect.void;
157
+ const path = testPath(context.sourceCode, node.callee);
158
+ const [first] = node.arguments;
159
+ if (["vi", "vitest"].includes(path[0] ?? "") && ["mock", "doMock"].includes(path[1] ?? "") && first !== void 0 && isStringLiteral(first)) mocked.add(first.value);
160
+ const callee = unwrapExpression(node.callee);
161
+ if (callee.type === "MemberExpression" && Option.getOrElse(memberPropertyName(callee), () => "").startsWith("toHaveBeenCalled")) {
162
+ let object = unwrapExpression(callee.object);
163
+ while (object.type === "MemberExpression") object = unwrapExpression(object.object);
164
+ if (object.type === "CallExpression" && testPath(context.sourceCode, object.callee)[0] === "expect") {
165
+ const [subject] = object.arguments;
166
+ if (subject !== void 0) Option.match(sourceOf(subject), {
167
+ onNone: () => void 0,
168
+ onSome: (source) => assertions.push({
169
+ node,
170
+ source
171
+ })
172
+ });
173
+ }
174
+ }
175
+ return Effect.void;
176
+ },
177
+ "Program:exit": () => Effect.forEach(assertions.filter(({ source }) => mocked.has(source) && local(source)), ({ node }) => context.report(Diagnostic.fromId({
178
+ node,
179
+ messageId: "behavior"
180
+ })), {
181
+ discard: true,
182
+ concurrency: 1
183
+ })
184
+ };
185
+ },
186
+ meta: Rule.meta({
187
+ description: "Local module mocks are not asserted through their call history",
188
+ messages: { behavior: "Run the real local module and assert its observable result. Delete the local vi.mock and the toHaveBeenCalled mirror." },
189
+ type: "problem"
190
+ }),
191
+ name: "no-mock-call-mirrors"
192
+ });
193
+ // src/rules/no-process-env.ts
194
+ const passesEnvironment = (node) => {
195
+ const parent = node.parent;
196
+ return parent.type === "SpreadElement" || (parent.type === "CallExpression" || parent.type === "NewExpression") && parent.arguments.includes(node) || parent.type === "VariableDeclarator" && parent.init === node && parent.id.type === "ObjectPattern" && Arr.some(parent.id.properties, (property) => property.type === "RestElement");
197
+ };
198
+ const isGlobalProcess = (source, node) => {
199
+ const lookup = (scope) => {
200
+ const variable = scope.set.get(node.name);
201
+ if (variable !== void 0 && variable.defs.length > 0) return false;
202
+ return scope.upper === null ? true : lookup(scope.upper);
203
+ };
204
+ return lookup(source.getScope(node));
205
+ };
206
+ const noProcessEnvRule = Rule.define({
207
+ name: "no-process-env",
208
+ meta: Rule.meta({
209
+ type: "suggestion",
210
+ description: "Read configuration through Effect Config",
211
+ messages: { config: "Read configuration through Effect Config. Passing the whole environment through is allowed." }
212
+ }),
213
+ *create() {
214
+ const context = yield* RuleContext;
215
+ return { MemberExpression: (node) => node.type === "MemberExpression" && node.object.type === "Identifier" && node.object.name === "process" && isGlobalProcess(context.sourceCode, node.object) && Option.contains(memberPropertyName(node), "env") && !passesEnvironment(node) ? context.report(Diagnostic.fromId({
216
+ node,
217
+ messageId: "config"
218
+ })) : Effect.void };
219
+ }
220
+ });
221
+ // src/rules/no-test-internal-imports.ts
222
+ const publicSubpath = (exports, subpath) => {
223
+ if (exports === void 0) return subpath === ".";
224
+ if (typeof exports === "string" || exports === null || Array.isArray(exports)) return subpath === "." && exports !== null;
225
+ if (typeof exports !== "object") return false;
226
+ if (!Object.keys(exports).some((key) => key.startsWith("."))) return subpath === ".";
227
+ const entries = Object.entries(exports);
228
+ const exact = entries.find(([key]) => key === subpath);
229
+ if (exact !== void 0) return exact[1] !== null;
230
+ const matched = entries.filter(([key]) => key.includes("*")).toSorted(([a], [b]) => {
231
+ const prefix = b.indexOf("*") - a.indexOf("*");
232
+ return prefix === 0 ? b.length - a.length : prefix;
233
+ }).find(([key]) => {
234
+ const [prefix, suffix] = key.split("*");
235
+ return subpath.startsWith(prefix ?? "") && subpath.endsWith(suffix ?? "");
236
+ });
237
+ return matched !== void 0 && matched[1] !== null;
238
+ };
239
+ const noTestInternalImportsRule = Rule.define({
240
+ *create() {
241
+ const context = yield* RuleContext;
242
+ if (!isTestFile(context.filename)) return {};
243
+ const folder = dirname(context.filename);
244
+ const own = packageAt(folder);
245
+ const internal = (source) => {
246
+ if (source.startsWith(".")) {
247
+ const target = resolve(folder, source);
248
+ if (dirname(target) === folder || /\/(?:tests?|__tests__)\//u.test(target)) return false;
249
+ return true;
250
+ }
251
+ const parts = source.split("/");
252
+ const name = source.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0] ?? "";
253
+ const subpath = source === name ? "." : `.${source.slice(name.length)}`;
254
+ if (source.startsWith("#")) return true;
255
+ if (Option.exists(own, ({ manifest }) => manifest.name === name && !publicSubpath(manifest.exports, subpath))) return true;
256
+ let directory = folder;
257
+ while (dirname(directory) !== directory) {
258
+ const dependency = manifestAt(join(directory, "node_modules", name));
259
+ if (Option.isSome(dependency)) return !publicSubpath(dependency.value.exports, subpath);
260
+ directory = dirname(directory);
261
+ }
262
+ return /(?:^|\/)(?:src|internal)\//u.test(source);
263
+ };
264
+ const check = (node) => isStringLiteral(node) && internal(node.value) ? context.report(Diagnostic.fromId({
265
+ node,
266
+ messageId: "public"
267
+ })) : Effect.void;
268
+ return {
269
+ ImportDeclaration: (node) => node.type === "ImportDeclaration" ? check(node.source) : Effect.void,
270
+ ImportExpression: (node) => node.type === "ImportExpression" ? check(node.source) : Effect.void,
271
+ CallExpression: (node) => node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments[0] !== void 0 ? check(node.arguments[0]) : Effect.void
272
+ };
273
+ },
274
+ meta: Rule.meta({
275
+ description: "Tests use public package exports unless colocated with their subject",
276
+ messages: { public: "Import the package's public entry point or exported subpath. Move this test beside its subject if it needs internal files." },
277
+ type: "problem"
278
+ }),
279
+ name: "no-test-internal-imports"
280
+ });
281
+ // src/rules/no-test-timeouts.ts
282
+ const noTestTimeoutsRule = Rule.define({
283
+ *create() {
284
+ const context = yield* RuleContext;
285
+ const test = isTestFile(context.filename);
286
+ const config = /(?:vitest|vite)\.config\.[cm]?[jt]s$/u.test(context.filename);
287
+ const report = (node) => context.report(Diagnostic.fromId({
288
+ node,
289
+ messageId: "remove"
290
+ }));
291
+ return {
292
+ Program: (node) => (test || config) && Option.exists(packageAt(dirname(context.filename)), ({ manifest }) => Object.values(manifest.scripts ?? {}).some((command) => /(?:^|\s)--retry(?:[=\s]|$)/u.test(command))) ? report(node) : Effect.void,
293
+ CallExpression: (node) => {
294
+ if (!test || node.type !== "CallExpression") return Effect.void;
295
+ const path = testPath(context.sourceCode, node.callee);
296
+ const overrides = node.arguments.some((argument) => argument.type === "ObjectExpression" && argument.properties.some((property) => property.type === "Property" && [
297
+ "timeout",
298
+ "testTimeout",
299
+ "hookTimeout",
300
+ "retry"
301
+ ].some((name) => Option.contains(propertyName(property), name))));
302
+ return isTestCall(context.sourceCode, node.callee) && (node.arguments.length > 2 || path.includes("retry") || overrides) || path.includes("setTimeout") || path.includes("setConfig") && overrides ? report(node) : Effect.void;
303
+ },
304
+ Property: (node) => config && node.type === "Property" && [
305
+ "timeout",
306
+ "testTimeout",
307
+ "hookTimeout",
308
+ "retry"
309
+ ].some((name) => Option.contains(propertyName(node), name)) ? report(node) : Effect.void,
310
+ Literal: (node) => (test || config) && node.type === "Literal" && typeof node.value === "string" && !(node.parent.type === "Property" && Option.contains(propertyName(node.parent), "code")) && /(?:^|\s)--retry(?:[=\s]|$)/u.test(node.value) ? report(node) : Effect.void
311
+ };
312
+ },
313
+ meta: Rule.meta({
314
+ description: "Tests use runner defaults without retries or timeout overrides",
315
+ messages: { remove: "Remove the test timeout or retry override. Fix the slow or flaky test and use the runner defaults." },
316
+ type: "problem"
317
+ }),
318
+ name: "no-test-timeouts"
319
+ });
320
+ // src/rules/no-test-waits.ts
321
+ const wallClock = /^(?:(?:globalThis\.)?(?:Date|performance)\s*(?:\.now|\[\s*["']now["']\s*\])|process\.hrtime(?:\.bigint)?)$/u;
322
+ const waits = /^(?:sleep|delay|setTimeout|setInterval|waitFor|waitUntil|waitForTimeout|waitForFunction|waitForNextUpdate|requestAnimationFrame|nextFrame|waitForFrame|poll|eventually|repeat|retry)$/u;
323
+ const noTestWaitsRule = Rule.define({
324
+ *create() {
325
+ const context = yield* RuleContext;
326
+ const report = (node) => context.report(Diagnostic.fromId({
327
+ node,
328
+ messageId: "synchronize"
329
+ }));
330
+ if (!isTestFile(context.filename)) return {};
331
+ return {
332
+ CallExpression: (node) => {
333
+ if (node.type !== "CallExpression") return Effect.void;
334
+ const callee = unwrapExpression(node.callee);
335
+ const name = Option.getOrElse(callee.type === "MemberExpression" ? memberPropertyName(callee) : lastName(callee), () => "");
336
+ const imported = importedPath(context.sourceCode, node.callee);
337
+ const path = testPath(context.sourceCode, node.callee);
338
+ const clock = context.sourceCode.getText(node.callee);
339
+ return waits.test(name) || path.includes("poll") || wallClock.test(clock) || Option.exists(imported, ({ source, members }) => source === "node:perf_hooks" && members.includes("now") || source === "node:process" && members.includes("hrtime") || waits.test(members.at(-1) ?? "") || members.includes("currentTimeMillis") || members.includes("currentTimeNanos")) ? report(node) : Effect.void;
340
+ },
341
+ MemberExpression: (node) => Option.exists(importedPath(context.sourceCode, node), ({ members }) => members.includes("currentTimeMillis") || members.includes("currentTimeNanos")) ? report(node) : Effect.void,
342
+ Identifier: (node) => node.type === "Identifier" && node.parent.type !== "ImportSpecifier" && Option.exists(importedPath(context.sourceCode, node), ({ members }) => members.includes("currentTimeMillis") || members.includes("currentTimeNanos")) ? report(node) : Effect.void,
343
+ NewExpression: (node) => node.type === "NewExpression" && (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0 || node.arguments.some((argument) => Option.exists(lastName(argument), (name) => waits.test(name)))) ? report(node) : Effect.void,
344
+ WhileStatement: (node) => node.type === "WhileStatement" && (node.test.type === "CallExpression" || node.test.type === "UnaryExpression" || node.test.type === "Literal" || /\bawait\b/u.test(context.sourceCode.getText(node.body))) ? report(node) : Effect.void,
345
+ DoWhileStatement: (node) => node.type === "DoWhileStatement" && (node.test.type === "CallExpression" || /\bawait\b/u.test(context.sourceCode.getText(node.body))) ? report(node) : Effect.void,
346
+ ForStatement: (node) => node.type === "ForStatement" && /\b(?:await|sleep|poll|retry|waitFor)\b/u.test(context.sourceCode.getText(node.body)) ? report(node) : Effect.void
347
+ };
348
+ },
349
+ meta: Rule.meta({
350
+ description: "Tests synchronize on observable completion rather than time or polling",
351
+ messages: { synchronize: "Remove the sleep, polling loop, wall-clock measurement or frame wait. Await the operation's completion or drive a controlled test clock." },
352
+ type: "problem"
353
+ }),
354
+ name: "no-test-waits"
355
+ });
93
356
  // src/shared/foldkit-api.ts
94
357
  const NAMESPACES = HashMap.make(["foldkit", []], ["foldkit/command", ["Command"]], ["foldkit/html", ["Html"]], ["foldkit/message", ["Message"]], ["foldkit/scene", ["Scene"]], ["foldkit/schema", ["Schema"]], ["foldkit/test", []]);
95
358
  const isFoldkitCall = (sourceCode, node, ...wanted) => Option.exists(importedPath(sourceCode, node.callee), (path) => Option.exists(HashMap.get(NAMESPACES, path.source), (prefix) => {
@@ -278,10 +541,43 @@ const requirePastTenseMessagesRule = Rule.define({
278
541
  }),
279
542
  name: "require-past-tense-messages"
280
543
  });
544
+ // src/rules/require-test-quarantine.ts
545
+ const requireTestQuarantineRule = Rule.define({
546
+ *create() {
547
+ const context = yield* RuleContext;
548
+ if (!isTestFile(context.filename)) return {};
549
+ const lines = context.sourceCode.text.split(/\r?\n/u);
550
+ return { CallExpression: (node) => {
551
+ if (node.type !== "CallExpression") return Effect.void;
552
+ const path = testPath(context.sourceCode, node.callee);
553
+ const skipped = [
554
+ "it",
555
+ "test",
556
+ "describe"
557
+ ].includes(path[0] ?? "") && path.some((name) => ["skip", "todo"].includes(name));
558
+ const line = node.loc.start.line;
559
+ return skipped && !/\bquarantine: #[1-9]\d*\b/u.test(lines[line - 2] ?? "") ? context.report(Diagnostic.fromId({
560
+ node,
561
+ messageId: "link"
562
+ })) : Effect.void;
563
+ } };
564
+ },
565
+ meta: Rule.meta({
566
+ description: "Skipped tests name their quarantine issue on the preceding line",
567
+ messages: { link: "Restore this test or put a void \"quarantine: #N\" statement on the line immediately above it, linking the issue that owns its repair." },
568
+ type: "problem"
569
+ }),
570
+ name: "require-test-quarantine"
571
+ });
281
572
  // src/plugin.ts
282
573
  const plugin = Plugin.define({
283
574
  name: "birbprophet",
284
575
  rules: {
576
+ "no-test-internal-imports": noTestInternalImportsRule,
577
+ "no-mock-call-mirrors": noMockCallMirrorsRule,
578
+ "require-test-quarantine": requireTestQuarantineRule,
579
+ "no-test-waits": noTestWaitsRule,
580
+ "no-test-timeouts": noTestTimeoutsRule,
285
581
  "no-comments": noCommentsRule,
286
582
  "no-process-env": noProcessEnvRule,
287
583
  "prefer-accessible-scene-locators": preferAccessibleSceneLocatorsRule,
package/dist/plugin.d.mts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { Plugin } from "effect-oxlint";
2
2
  declare const plugin: Plugin.DefinedPlugin<{
3
+ readonly "no-test-internal-imports": import("effect-oxlint").CreateRule;
4
+ readonly "no-mock-call-mirrors": import("effect-oxlint").CreateRule;
5
+ readonly "require-test-quarantine": import("effect-oxlint").CreateRule;
6
+ readonly "no-test-waits": import("effect-oxlint").CreateRule;
7
+ readonly "no-test-timeouts": import("effect-oxlint").CreateRule;
3
8
  readonly "no-comments": import("effect-oxlint").CreateRule;
4
9
  readonly "no-process-env": import("effect-oxlint").CreateRule;
5
10
  readonly "prefer-accessible-scene-locators": import("effect-oxlint").CreateRule;
package/dist/plugin.mjs CHANGED
@@ -1 +1 @@
1
- export { t as default } from "./plugin-DwQM07Ih.mjs";
1
+ export { t as default } from "./plugin-DUUAfi92.mjs";