Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔧 chore(alint): flag self-proving and subsumed test cases (#22335)

Inneia1af6ec231d1
diff --git a/alint.config.toml b/alint.config.toml
index 2c822e1b607..4720f882abe 100644
--- a/alint.config.toml
+++ b/alint.config.toml
@@ -251,6 +251,22 @@ lobehub = "./packages/alint/rules"
[config.group.rules]
"lobehub/no-removal-only-tests" = "warn"
"lobehub/no-constant-stub-tests" = "warn"
+"lobehub/no-self-proving-tests" = "warn"
+"lobehub/no-redundant-test-cases" = "warn"
+
+[[config.group]]
+files = [ "packages/alint/fixtures/no-self-proving-tests/**" ]
+[config.group.plugins]
+lobehub = "./packages/alint/rules"
+[config.group.rules]
+"lobehub/no-self-proving-tests" = "warn"
+
+[[config.group]]
+files = [ "packages/alint/fixtures/no-redundant-test-cases/**" ]
+[config.group.plugins]
+lobehub = "./packages/alint/rules"
+[config.group.rules]
+"lobehub/no-redundant-test-cases" = "warn"
# Ordinary API instructions: avoid removal announcements and locally redundant
# descriptions while preserving migration guidance and useful input semantics.
diff --git a/packages/alint/README.md b/packages/alint/README.md
index 6033e2b6e6d..d9102954363 100644
--- a/packages/alint/README.md
+++ b/packages/alint/README.md
@@ -31,6 +31,9 @@ This is Phase 0: the rule set is a private workspace package (`@lobechat/alint`)
| `no-prototype-pollution` | warn | server, desktop main, shared utilities | untrusted keys/paths reaching prototype setters |
| `no-privileged-untrusted-electron` | warn | Electron main/preload | remote content with Node privileges or unrestricted IPC bridges |
| `no-removal-only-tests` | warn | app/package/client test and spec files | tests should prove behavior, not merely that a retired option is absent |
+| `no-constant-stub-tests` | warn | app/package/client test and spec files | fixed responses from inert endpoints do not add behavior coverage |
+| `no-self-proving-tests` | warn | app/package/client test and spec files | mock round-trips, copied implementations and private declaration replay |
+| `no-redundant-test-cases` | warn | app/package/client test and spec files | a stronger same-file check already proves the same outcome and state |
| `no-redundant-api-copy` | warn | usage guides, builtin skills, CLI commands, public schemas | keep ordinary instructions focused on supported actions |
| `static-app-image-namespace` | warn | web client, image URL helpers and asset packaging | fixed product images use `/static/app-images` |
@@ -49,6 +52,11 @@ Package-level rules, kept next to the package they describe:
Scopes are declared as `[[config.group]]` entries in the root `alint.config.toml`. Never scope a rule with `includeFiles` inside `rule.alint.toml`: it only filters reports, so every file still runs (double the jobs), and it marks the rule uncacheable.
+The test-value rules use only the supplied file: duplicate-proof findings must name a
+stronger retained check, and declaration-only findings must exclude independent
+protocol, registration and policy contracts. Local model calibration does not establish
+precision on CI's DeepSeek provider; both new rules stay at `warn`.
+
## Where a rule lives
Rules come in two layers, and each layer is registered as its own plugin in `alint.config.toml`:
diff --git a/packages/alint/fixtures/no-redundant-test-cases/bad-repeated-assertion.ts b/packages/alint/fixtures/no-redundant-test-cases/bad-repeated-assertion.ts
new file mode 100644
index 00000000000..b9c18848ad6
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/bad-repeated-assertion.ts
@@ -0,0 +1,14 @@
+import { expect, it } from 'vitest';
+
+const legacyMode = 'minimal';
+const newMode = 'none';
+
+it('keeps the legacy default', () => {
+ expect(legacyMode).toBe('minimal');
+});
+
+// alint-expect
+it('starts new items quietly', () => {
+ expect(newMode).toBe('none');
+ expect(legacyMode).toBe('minimal');
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/bad-subsumed-result.ts b/packages/alint/fixtures/no-redundant-test-cases/bad-subsumed-result.ts
new file mode 100644
index 00000000000..9a837b03713
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/bad-subsumed-result.ts
@@ -0,0 +1,15 @@
+import { expect, it } from 'vitest';
+
+const defaults = (settings?: { enabled?: boolean }) => ({
+ enabled: settings?.enabled ?? true,
+ mode: 'quiet',
+});
+
+it('creates all defaults when settings are omitted', () => {
+ expect(defaults(undefined)).toEqual({ enabled: true, mode: 'quiet' });
+});
+
+// alint-expect
+it('enables an item when settings are omitted', () => {
+ expect(defaults(undefined).enabled).toBe(true);
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-diagnostic-preconditions.ts b/packages/alint/fixtures/no-redundant-test-cases/good-diagnostic-preconditions.ts
new file mode 100644
index 00000000000..59ee88860b0
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-diagnostic-preconditions.ts
@@ -0,0 +1,18 @@
+import { expect, it } from 'vitest';
+
+declare const readRun: () => Promise<{ metadata: { summary: string } } | undefined>;
+declare const completionHook: () => { handler: () => void } | undefined;
+
+it('reads the persisted summary', async () => {
+ const run = await readRun();
+
+ expect(run).toBeDefined();
+ expect(run!.metadata).toMatchObject({ summary: 'done' });
+});
+
+it('registers a callable completion hook', () => {
+ const hook = completionHook();
+
+ expect(hook).toBeDefined();
+ expect(hook!.handler).toBeInstanceOf(Function);
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-different-effects.ts b/packages/alint/fixtures/no-redundant-test-cases/good-different-effects.ts
new file mode 100644
index 00000000000..1548e1dc4be
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-different-effects.ts
@@ -0,0 +1,16 @@
+import { expect, it, vi } from 'vitest';
+
+const save = (record: string, persist: (value: string) => void) => {
+ persist(record.trim());
+ return { saved: true };
+};
+
+it('reports successful saving', () => {
+ expect(save(' hello ', vi.fn())).toEqual({ saved: true });
+});
+
+it('persists the normalized record', () => {
+ const persist = vi.fn();
+ save(' hello ', persist);
+ expect(persist).toHaveBeenCalledWith('hello');
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-different-inputs.ts b/packages/alint/fixtures/no-redundant-test-cases/good-different-inputs.ts
new file mode 100644
index 00000000000..ca4c025003d
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-different-inputs.ts
@@ -0,0 +1,11 @@
+import { expect, it } from 'vitest';
+
+const defaults = (settings?: { enabled?: boolean }) => ({ enabled: settings?.enabled ?? true });
+
+it('uses the default for omitted settings', () => {
+ expect(defaults(undefined)).toEqual({ enabled: true });
+});
+
+it('preserves an explicit opt-out', () => {
+ expect(defaults({ enabled: false })).toEqual({ enabled: false });
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-independent-errors.ts b/packages/alint/fixtures/no-redundant-test-cases/good-independent-errors.ts
new file mode 100644
index 00000000000..e0805ecf359
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-independent-errors.ts
@@ -0,0 +1,15 @@
+import { expect, it } from 'vitest';
+
+const parse = (input: string) => {
+ if (!input) throw new Error('missing');
+ if (input.includes('/')) throw new Error('invalid path');
+ return input;
+};
+
+it('rejects a missing value', () => {
+ expect(() => parse('')).toThrow('missing');
+});
+
+it('rejects a path', () => {
+ expect(() => parse('a/b')).toThrow('invalid path');
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-parameterized-boundaries.ts b/packages/alint/fixtures/no-redundant-test-cases/good-parameterized-boundaries.ts
new file mode 100644
index 00000000000..70d4d3a7982
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-parameterized-boundaries.ts
@@ -0,0 +1,12 @@
+import { expect, it } from 'vitest';
+
+const accepts = (size: number) => size > 0 && size <= 100;
+
+it.each([
+ [0, false],
+ [1, true],
+ [100, true],
+ [101, false],
+])('accepts size %i: %s', (size, expected) => {
+ expect(accepts(size)).toBe(expected);
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-provider-contracts.ts b/packages/alint/fixtures/no-redundant-test-cases/good-provider-contracts.ts
new file mode 100644
index 00000000000..46b2ad80e3f
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-provider-contracts.ts
@@ -0,0 +1,14 @@
+import { expect, it } from 'vitest';
+
+const registered = new Map([
+ ['alpha', { endpoint: 'https://alpha.example/v1' }],
+ ['beta', { endpoint: 'https://beta.example/v1' }],
+]);
+
+it('uses the Alpha provider endpoint', () => {
+ expect(registered.get('alpha')?.endpoint).toBe('https://alpha.example/v1');
+});
+
+it('uses the Beta provider endpoint', () => {
+ expect(registered.get('beta')?.endpoint).toBe('https://beta.example/v1');
+});
diff --git a/packages/alint/fixtures/no-redundant-test-cases/good-state-change.ts b/packages/alint/fixtures/no-redundant-test-cases/good-state-change.ts
new file mode 100644
index 00000000000..4307acca00c
--- /dev/null
+++ b/packages/alint/fixtures/no-redundant-test-cases/good-state-change.ts
@@ -0,0 +1,13 @@
+import { expect, it } from 'vitest';
+
+let enabled = false;
+const read = () => ({ enabled });
+
+it('starts disabled', () => {
+ expect(read().enabled).toBe(false);
+});
+
+it('returns the updated value after enabling', () => {
+ enabled = true;
+ expect(read()).toEqual({ enabled: true });
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/bad-copied-implementation.ts b/packages/alint/fixtures/no-self-proving-tests/bad-copied-implementation.ts
new file mode 100644
index 00000000000..38bbd2bd38b
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/bad-copied-implementation.ts
@@ -0,0 +1,9 @@
+import { expect, it } from 'vitest';
+
+// Copied from the production adapter. The production adapter is never imported.
+const localAdapter = (input: string) => input.trim().toLowerCase();
+
+// alint-expect
+it('normalizes the production adapter input', () => {
+ expect(localAdapter(' HELLO ')).toBe('hello');
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/bad-mirrored-expectation.ts b/packages/alint/fixtures/no-self-proving-tests/bad-mirrored-expectation.ts
new file mode 100644
index 00000000000..7a30bd6b13a
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/bad-mirrored-expectation.ts
@@ -0,0 +1,9 @@
+import { expect, it } from 'vitest';
+
+const buildQuery = (tag: string) => ({ query: `tag:${tag}` });
+
+// alint-expect
+it('builds the expected tag query', () => {
+ const expected = buildQuery('urgent');
+ expect(buildQuery('urgent')).toEqual(expected);
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/bad-mock-roundtrip.ts b/packages/alint/fixtures/no-self-proving-tests/bad-mock-roundtrip.ts
new file mode 100644
index 00000000000..583dd44b69f
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/bad-mock-roundtrip.ts
@@ -0,0 +1,8 @@
+import { expect, it, vi } from 'vitest';
+
+const loadSettings = vi.fn().mockResolvedValue({ reactionMode: 'none' });
+
+// alint-expect
+it('loads the configured reaction mode', async () => {
+ expect(await loadSettings()).toEqual({ reactionMode: 'none' });
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/bad-private-table.ts b/packages/alint/fixtures/no-self-proving-tests/bad-private-table.ts
new file mode 100644
index 00000000000..b0995184417
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/bad-private-table.ts
@@ -0,0 +1,15 @@
+import { expect, it } from 'vitest';
+
+// Private presentation metadata, with no exported protocol or registration contract.
+const fields = {
+ prompt: { component: 'textarea', order: 0 },
+ width: { component: 'number', order: 1 },
+};
+
+// alint-expect
+it('keeps the internal field declarations', () => {
+ expect(fields).toEqual({
+ prompt: { component: 'textarea', order: 0 },
+ width: { component: 'number', order: 1 },
+ });
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/good-boundary-callback.ts b/packages/alint/fixtures/no-self-proving-tests/good-boundary-callback.ts
new file mode 100644
index 00000000000..a596edad58d
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/good-boundary-callback.ts
@@ -0,0 +1,11 @@
+import { expect, it, vi } from 'vitest';
+
+const submit = (draft: string, save: (value: string) => void) => {
+ if (draft.trim()) save(draft.trim());
+};
+
+it('sends normalized content to the persistence boundary', () => {
+ const save = vi.fn();
+ submit(' hello ', save);
+ expect(save).toHaveBeenCalledWith('hello');
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/good-idempotence.ts b/packages/alint/fixtures/no-self-proving-tests/good-idempotence.ts
new file mode 100644
index 00000000000..23c5344fca8
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/good-idempotence.ts
@@ -0,0 +1,8 @@
+import { expect, it } from 'vitest';
+
+const normalize = (input: string) => input.trim().toLowerCase();
+
+it('is idempotent for already normalized content', () => {
+ const normalized = normalize(' HELLO ');
+ expect(normalize(normalized)).toBe(normalized);
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/good-independent-policy.ts b/packages/alint/fixtures/no-self-proving-tests/good-independent-policy.ts
new file mode 100644
index 00000000000..c128abd1d20
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/good-independent-policy.ts
@@ -0,0 +1,8 @@
+import { expect, it } from 'vitest';
+
+// Published protocol: these identifiers are consumed by separately deployed clients.
+const protocolKinds = { approval: 'tool_approval', question: 'question' } as const;
+
+it('preserves the published approval wire identifier', () => {
+ expect(protocolKinds.approval).toBe('tool_approval');
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/good-normalization.ts b/packages/alint/fixtures/no-self-proving-tests/good-normalization.ts
new file mode 100644
index 00000000000..d7b9dbc94a4
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/good-normalization.ts
@@ -0,0 +1,7 @@
+import { expect, it } from 'vitest';
+
+const normalize = (input: string) => input.trim().toLowerCase();
+
+it('normalizes whitespace and case', () => {
+ expect(normalize(' HELLO ')).toBe('hello');
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/good-stateful-mock.ts b/packages/alint/fixtures/no-self-proving-tests/good-stateful-mock.ts
new file mode 100644
index 00000000000..3cc5cc06086
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/good-stateful-mock.ts
@@ -0,0 +1,15 @@
+import { expect, it, vi } from 'vitest';
+
+const retry = async (request: () => Promise<string>) => {
+ try {
+ return await request();
+ } catch {
+ return request();
+ }
+};
+
+it('recovers from the first request failure', async () => {
+ const request = vi.fn().mockRejectedValueOnce(new Error('offline')).mockResolvedValue('ready');
+ expect(await retry(request)).toBe('ready');
+ expect(request).toHaveBeenCalledTimes(2);
+});
diff --git a/packages/alint/fixtures/no-self-proving-tests/good-uncertain-import.ts b/packages/alint/fixtures/no-self-proving-tests/good-uncertain-import.ts
new file mode 100644
index 00000000000..f1771b6d031
--- /dev/null
+++ b/packages/alint/fixtures/no-self-proving-tests/good-uncertain-import.ts
@@ -0,0 +1,7 @@
+import { expect, it } from 'vitest';
+
+declare const readPreferences: () => Promise<{ mode: string }>;
+
+it('reads the stored preference through its owner', async () => {
+ expect(await readPreferences()).toEqual({ mode: 'quiet' });
+});
diff --git a/packages/alint/rules/no-redundant-test-cases/rule.alint.toml b/packages/alint/rules/no-redundant-test-cases/rule.alint.toml
new file mode 100644
index 00000000000..799309188a5
--- /dev/null
+++ b/packages/alint/rules/no-redundant-test-cases/rule.alint.toml
@@ -0,0 +1,14 @@
+name = "no-redundant-test-cases"
+builtInAgent = "basic-structured"
+instruction = """
+Review one test file for subsumed proof. Owner rule (verbatim): "Prefer behavior-oriented tests and regression tests that validate externally meaningful outcomes, decision boundaries, or previously failing edge cases."
+
+Return no finding for different inputs, providers, permissions, error categories, execution modes, lifecycle/state transitions, ordering or side effects. Parameterized rows do not become redundant just because they share a code branch. Registration/protocol/security boundaries can be independent contracts. Never assume an imported function is pure or that two setups are equivalent when the file does not establish it.
+
+Return no finding for existence/non-null assertions on an already computed value immediately followed by dereferencing that value to verify its fields in the same case (for example toBeDefined before reading metadata or a handler). These improve failure diagnostics. This exemption does not cover length/state assertions, repeated expected field values, constants, or separate test cases.
+
+Report only when a stronger retained assertion or case IN THIS FILE already proves every outcome of another check with equivalent inputs, setup and relevant state. The narrower check must add no independent assertion, side effect, regression boundary or lifecycle observation. Same-input repeated assertions inside an otherwise useful case can be reported only as a removable fragment; retain the rest.
+
+Anchor once on the redundant case's it/test declaration. Name the stronger retained case/lines, the equivalent inputs/state, and the exact subsumed assertion. Suggest only the minimal deletion, explicitly preserving any independent assertions. Equal coverage, similar titles, equal outputs on different inputs, or a mock returning the same fixture are not sufficient evidence.
+If setup equivalence or subsumption is uncertain, return no finding. Do not demand replacement tests for proof that remains covered.
+"""
diff --git a/packages/alint/rules/no-self-proving-tests/rule.alint.toml b/packages/alint/rules/no-self-proving-tests/rule.alint.toml
new file mode 100644
index 00000000000..9239d8a8aa4
--- /dev/null
+++ b/packages/alint/rules/no-self-proving-tests/rule.alint.toml
@@ -0,0 +1,16 @@
+name = "no-self-proving-tests"
+builtInAgent = "basic-structured"
+instruction = """
+Review one test file. Owner rule (verbatim): "Do not write implementation-snapshot tests that merely restate internal constant tables, whitelist declarations, object literals, or similarly static structures when those tests provide no independent behavioral signal."
+
+Return no finding for independent public/protocol identifiers, provider registration or architecture/security policies, normalization/validation, state changes, persistence, recovery, dependency-boundary arguments, or legitimate metamorphic invariants such as idempotence. A mock used by real code is not itself a problem. A locally defined function is not evidence of a copied implementation. Do not guess what imported code does.
+
+Report only a case whose supplied evidence establishes one of:
+- The test calls a configured mock directly and merely compares its canned result, without an intervening real consumer.
+- An explicitly copied production implementation is reimplemented and tested locally, while the real implementation is never exercised.
+- Actual and expected are computed by the same deterministic helper with the same inputs; there is no independently derived result or metamorphic property.
+- The entire case only copies explicitly private static declaration data into an expected object/list, with no independent behavioral, registration, protocol or policy contract.
+
+Anchor once on the it/test declaration. Name exactly what is self-proving and why a broken production consumer could still pass. Suggest removing the redundant check/setup or exercising its real consumer with an independent expected outcome. Preserve useful assertions in mixed cases; do not report the entire case when it also proves real behavior. Duplicate proof already present in another case belongs to no-redundant-test-cases.
+If the lack of an independent contract is uncertain, return no finding.
+"""