Files
msd-core/tests/no-unconfined-path-join.rule.test.cjs
Tom Boucher bbdf7e8e84 chore(#4654): add local/no-unconfined-path-join and drain it to zero — Phase 4 of #4636 (#4674)
* chore(#4654): add local/no-unconfined-path-join and drain it to zero

Phase 4 of epic #4636 — the ratchet, and the phase that makes the epic hold.

THE MEASUREMENT THAT RESHAPED THE PHASE. An AST census (the repo's own parser,
not grep) found what the epic never enumerated: ADR-4650 named seven containment
implementations; `src/` alone held roughly 24 more hand-rolled gates across ~13
files, several guarding a write or an `fs.rmSync`. Two verified by reading rather
than pattern-matching — `research-store.cts` comments its own as "ensure the
resolved file path stays inside the store dir" immediately before a write, and
`capability-lifecycle.cts` gates `fs.rmSync` with one.

So the epic's Done-when "one containment predicate, used at every site" was FALSE
when Phase 3 reported it satisfied. It is true now: the rule is clean across
src/, scripts/, gsd-core/bin/ and hooks/ with an EMPTY allowlist.

WHY NOT THE RULE THE ISSUE PROPOSED. #4654 proposed flagging `path.join` whose
first argument is a managed root and whose later arguments derive from argv. That
is a taint analysis over 2046 call sites, in ESLint, without type information;
"derives from argv" is not locally decidable. Any approximation either floods or
is trivially evaded, and a rule that fires on hundreds of correct sites earns an
allowlist of hundreds — the opposite of a ratchet. What is actually duplicated is
the COMPARISON, not the join, and that has one recognizable shape.

  Arm 1  X.startsWith(Y + sep)            the hand-rolled containment idiom
  Arm 2  a containment predicate called as a bare statement, answer discarded

Arm 2 is the issue's "asserts the result was narrowed, not merely that a helper
was called". Its example `validatePath(x, root).resolved` is already
structurally impossible — Phase 3 un-exported `validatePath` — so the remaining
expressible failure is ignoring the answer, which is the defect that recurred
five times in this epic. The census found exactly one live instance
(`milestone.cts:1643`); it now returns the proven `ContainedPath` so consumers
stop re-deriving the path the comment above it was extracted to stop them
re-deriving.

The rule deliberately does NOT try to catch validate-one-path-use-another where
the answer is used but a different variable flows onward. That needs flow
analysis; the branded `ContainedPath` from Phase 3 is the defense there, and the
two are complementary.

PER-SITE FAMILY CHOICE, NOT A DEFAULT. Phase 3's lesson binds: collapsing a
lexical site onto the realpath family broke four tests and was caught only by the
matrix. Every migrated site was triaged individually. The six
installer-migrations tree-walks and the six capability-lifecycle gates take the
LEXICAL family because their operands are already realpath-resolved and they
deliberately treat the final component as a link; boundary sites take realpath.

TWO SITES WITH AN INVERTED CONTRACT, which a mechanical swap would have broken.
`installer-migrations.cts:127` and `runtime-artifact-install-plan.cts:144` REJECT
`target === root` by contract, while the canonical comparison ACCEPTS it. Swapped
naively, a migration could `rmdir` the user's config root and a third-party
descriptor could write at configHome itself. Both keep `=== root` as an explicit
additional arm alongside the predicate call — the predicate decides containment,
the call site keeps its own extra condition (ADR-4650 decision 6).

ONE DUPLICATE DELETED OUTRIGHT: `planning-inspect.cts`'s `isWithinRoot` was
byte-identical to `isContainedIn` and said so in its own docstring.
`isContainedIn` is now exported for callers that have already resolved both
operands and need only the comparison, with a doc note that a caller which has
NOT resolved them must use a full predicate instead.

THE MARKER, AND WHY IT IS NOT THE ALLOWLIST. Nine sites are justified holdouts and
carry `// allow-handrolled-containment: <reason>` with a mandatory, reviewable
reason. Two justifications: (a) not a containment decision — an ancestor-walk loop
condition, sub-repo grouping, worktree identity matching, declared-path coverage;
(b) it IS containment but the canonical predicate is unreachable —
`capability-validator.cjs` is a committed pre-build `.cjs` and the compiled
`security.cjs` is untracked build output, so requiring it would break a fresh
clone. `scripts/lib/drift-scan.cjs` runs under `lint:ci` with the same exposure.
The marker was renamed from `allow-lexical-prefix-match` mid-phase because that
name asserted only (a) and would have stated something false at the (b) sites.

A marker suppresses BEFORE the violation counter increments, so a file whose
every occurrence is marked still reports `staleAllowlistEntry` — otherwise a
drained entry lingers and silently re-permits the site later.

DEMONSTRATED RED, per #4654: a hand-rolled copy reintroduced into a real `src/`
file made `npm run lint` fail with the rule's full guidance message; removing it
returned the tree to clean. Both halves recorded — red alone proves nothing,
since a rule red for an unrelated reason looks identical.

DISCLOSED: `defaultRequireFromInstallRoot` (gsd-tools.cjs) previously carried two
distinct rejection messages and two manual realpath calls; routing it through
`tryWithinRoot` collapses them to one message, and a missing module now surfaces
as MODULE_NOT_FOUND rather than ENOENT. No test asserts either message. The
security property is preserved and slightly strengthened — the candidate is
realpathed and containment re-checked, and the dangling-symlink oracle closure
comes along with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(#4654): record the containment ratchet in CONTEXT.md and the security model

Both entries previously described the seam without the thing that keeps it a
seam. They now state what the rule bans, and — more usefully for whoever reads
this next — what it deliberately does NOT attempt: deciding per path.join call
whether an argument came from user input. That question is not locally
decidable, and an approximation across ~2000 join sites would earn an exemption
list of hundreds, which is the opposite of a ratchet.

Also records the marker's two legitimate justifications and that its reason is
mandatory, so the escape stays reviewable rather than becoming a mute button.

Glossary gate 270 refs exit 0; install-tree goldens and CONTEXT-INDEX.json
regenerated and confirmed byte-identical rather than assumed — which also
confirms eslint-rules/ is not a shipped path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(#4654): close review findings and the two matrix failures

MATRIX FAILURE 1 — a collapsed message broke a negative-proof test, and my
evidence for collapsing it was wrong. I searched tests/ for the literal string
"resolves outside its install root", found nothing, and reported that no test
asserted it. The test matches a REGEX SUBSTRING, /outside its install root/, so
the literal search missed it. What broke was "NEGATIVE PROOF: a symlinked module
pointing OUTSIDE the install root is not loaded" — the test guarding the exact
property I claimed was preserved. defaultRequireFromInstallRoot now does both
checks again with both messages byte-identical, each routed through the
canonical predicate, which is better than the original since that hand-rolled
both comparisons.

MATRIX FAILURE 2 — shipped migrations are checksum-locked, and a marker cannot
serve there. migrationChecksum hashes plan.toString(), which INCLUDES comments,
so a suppression marker inside a plan body drifts the baseline exactly as an
edit does. Measured: with markers in place, two of the four still differed from
their committed checksums. The four shipped bodies are now byte-identical to
next, and the rule's config excludes those four paths BY NAME rather than by a
directory wildcard, so a NEW migration is still covered. Six containment
comparisons stay un-ratcheted there; that gap is recorded in the rule's Known
gaps, in CONTEXT.md and in the security model rather than left implicit.
Justification (c) is removed from the marker's documented reasons, because a
marker was proven unable to express it.

ADVERSARIAL REVIEW — the sharpest finding was that the rule banned the CORRECT
shape while permitting the incorrect one: startsWith(root) with no separator is
the genuinely unsafe form, since it accepts a sibling such as root-evil, and my
own test blessed it as valid. Flagging every bare startsWith would swamp the
rule, so that stays a STATED gap rather than a silent one. Closed for real: the
template-literal spelling, which the census never saw because it only inspected
plus-concatenation — that surfaced TWELVE more sites, now triaged and migrated.
A separator reached through a const alias is now resolved via scope analysis.
And isContainedIn, exported in Phase 3, was missing from the discarded-result
set, so a bare no-op call went unflagged on the one function the epic funnels
through.

SECURITY REVIEW — the marker could over-suppress two ways: a block comment
worked identically to a line comment, and one marker silently covered every
violation sharing its line. It now requires a Line comment positioned after the
flagged node ends, so it anchors to the node it trails. Four sites had dropped
an unreachable-but-deliberate equality rejection against the root; each is
restored as the call site's own arm. eslint.config.mjs still documented the OLD
marker token, which my rename missed — it would have sent the next author in
circles.

A FALSE GREEN, recorded because it nearly stuck: lint:ci reported exit 0 from a
stale eslint cache while twelve real violations existed. Every lint check here
now clears the cache first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(#4654): anchor a suppression marker to the violation it actually trails

The matrix caught this; my own test caught it, on its first execution. The case
"two violations on one line: trailing marker suppresses only the one it trails"
expected 1 error and got 0 — both were suppressed.

ROOT CAUSE: the anchoring accepted any Line comment on the node's line whose
range started at or after the node's end. A trailing marker at the END of a line
sits after EVERY node on that line, so that condition held for all of them.
"After the node" does not identify WHICH node the marker trails. The fix reads
as correct and is not.

FIX: deferred reporting. Violations accumulate during traversal instead of being
reported immediately; at Program:exit each marker claims exactly ONE pending
violation — the one on its line whose end is nearest before the marker begins —
and every unclaimed violation is then counted and reported. One marker, one
suppression. An earlier violation sharing the line is still reported, which is
the property the security review asked for and the previous attempt only
appeared to deliver.

The counter now increments at flush time rather than during traversal, so a
suppressed occurrence still does not keep an allowlist entry alive.

AND A TOOL THAT SHOULD HAVE EXISTED BEFORE THE FIRST MATRIX RUN. `node --test`
is hard-blocked here, so this rule's test file could only ever be executed on
the remote matrix — which is why a broken anchoring shipped into a run. ESLint's
programmatic Linter API is not a test runner, and exercising the rule through it
verifies every case locally in seconds. All 24 now pass locally, including the
two-on-one-line case that failed remotely. That loop should have been built
before the rule was first sent to the matrix rather than after it failed twice.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore(#4654): backfill PR 4674 into the changeset and complete 70-docs.json

The phase gate requires enablementSequence and the Diataxis quadrants; 70-docs
now carries both, with the how-to quadrant skipped for a stated reason rather
than an empty field. The audience for this deliverable is a contributor who
trips the rule, and the task-oriented guidance reaches them in the ESLint
message itself — which names the correct predicate, says how to choose between
the realpath and lexical families, cites the Phase 3 regression caused by
choosing wrong, and gives the marker syntax. A docs/how-to page would be a
second, driftable copy read by nobody at the moment of failure.

enablementSequence is recorded as what it actually is: a VERIFICATION sequence,
not an enablement one. The rule is never off, so there is no off-to-on
transition to describe.

scripts/lint-docs-required.cjs now passes (ok_docs_updated) — it could not
evaluate against the mandated pr:0 placeholder.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: sim <sim@local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 22:17:46 -04:00

500 lines
16 KiB
JavaScript

'use strict';
/**
* no-unconfined-path-join.rule.test.cjs
*
* RuleTester unit tests for the local/no-unconfined-path-join ESLint rule.
*
* Arm 1: hand-rolled containment comparison `x.startsWith(y + sep)`.
* Arm 2: a discarded containment-predicate result (bare statement call).
* Plus the `allow-handrolled-containment: <reason>` marker escape and the
* allowlist ratchet mechanics.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const { RuleTester } = require('eslint');
const rule = require('../eslint-rules/no-unconfined-path-join.cjs');
const ruleTester = new RuleTester({
languageOptions: {
ecmaVersion: 2022,
sourceType: 'commonjs',
},
});
// ─── module shape ─────────────────────────────────────────────────────────────
describe('no-unconfined-path-join rule module', () => {
test('exports meta and create', () => {
assert.strictEqual(typeof rule.meta, 'object');
assert.strictEqual(typeof rule.create, 'function');
assert.strictEqual(rule.meta.type, 'problem');
assert.ok(rule.meta.messages.handRolledContainment, 'handRolledContainment message must exist');
assert.ok(
rule.meta.messages.discardedContainmentResult,
'discardedContainmentResult message must exist',
);
assert.ok(rule.meta.messages.staleAllowlistEntry, 'staleAllowlistEntry message must exist');
});
});
// ─── Arm 1: hand-rolled containment — fires ──────────────────────────────────
describe('no-unconfined-path-join: arm 1 fires', () => {
test('invalid: resolved.startsWith(root + path.sep)', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep);`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: resolved !== root && !resolved.startsWith(root + path.sep) reports exactly one error', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `if (resolved !== root && !resolved.startsWith(root + path.sep)) { throw new Error('x'); }`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: x.startsWith(y + "/")', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `x.startsWith(y + '/');`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: x.startsWith(y + "\\\\")', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `x.startsWith(y + '\\\\');`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: x.startsWith(y + p.sep)', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `x.startsWith(y + p.sep);`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: x.startsWith(`${root}${path.sep}`) — template literal ending in a `.sep` expression', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: 'x.startsWith(`${root}${path.sep}`);',
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: x.startsWith(`${root}/`) — template literal ending in a literal separator character', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: 'x.startsWith(`${root}/`);',
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: const sep = path.sep; x.startsWith(root + sep) — separator reached through a single const alias', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: 'const sep = path.sep; x.startsWith(root + sep);',
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
});
// ─── Arm 1: hand-rolled containment — silent ─────────────────────────────────
describe('no-unconfined-path-join: arm 1 silent', () => {
test('valid: x.startsWith(prefix) — bare identifier argument', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `x.startsWith(prefix);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: x.startsWith("gsd-") — plain literal argument', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `x.startsWith('gsd-');`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: x.startsWith(y + "-") — right side is not a separator', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `x.startsWith(y + '-');`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: x.startsWith(y + z) — right side is an unresolvable identifier', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `x.startsWith(y + z);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: let sep = path.sep; x.startsWith(root + sep) — reassignable `let` binding is not resolved', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `let sep = path.sep; x.startsWith(root + sep);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: function f(sep) { x.startsWith(root + sep); } — parameter binding is not resolved', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{ code: `function f(sep) { x.startsWith(root + sep); }`, filename: 'src/foo.cts' },
],
invalid: [],
});
});
test('valid: x.startsWith(a, b) — wrong arity', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `x.startsWith(a, b);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: x.startsWith(`${root}-suffix`) — template literal NOT ending in a separator', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: 'x.startsWith(`${root}-suffix`);', filename: 'src/foo.cts' }],
invalid: [],
});
});
});
// ─── Arm 2: discarded containment result — fires ─────────────────────────────
describe('no-unconfined-path-join: arm 2 fires', () => {
test('invalid: assertWithinRoot(p, root); as a bare statement', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `assertWithinRoot(p, root);`,
filename: 'src/foo.cts',
errors: [{ messageId: 'discardedContainmentResult' }],
},
],
});
});
test('invalid: tryWithinRoot(p, root); as a bare statement', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `tryWithinRoot(p, root);`,
filename: 'src/foo.cts',
errors: [{ messageId: 'discardedContainmentResult' }],
},
],
});
});
test('invalid: isContainedIn(p, root); as a bare statement — boolean predicate discarded', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `isContainedIn(p, root);`,
filename: 'src/foo.cts',
errors: [{ messageId: 'discardedContainmentResult' }],
},
],
});
});
});
// ─── Arm 2: discarded containment result — silent ────────────────────────────
describe('no-unconfined-path-join: arm 2 silent', () => {
test('valid: const x = assertWithinRoot(p, root); — VariableDeclarator init', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `const x = assertWithinRoot(p, root);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
test('valid: if (tryWithinRoot(p, root) === null) {} — inside a comparison', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{ code: `if (tryWithinRoot(p, root) === null) {}`, filename: 'src/foo.cts' },
],
invalid: [],
});
});
test('valid: return assertWithinRoot(p, root); — return value', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{
code: `function f() { return assertWithinRoot(p, root); }`,
filename: 'src/foo.cts',
},
],
invalid: [],
});
});
test('valid: fs.readFileSync(assertWithinRoot(p, root)); — call argument', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{ code: `fs.readFileSync(assertWithinRoot(p, root));`, filename: 'src/foo.cts' },
],
invalid: [],
});
});
test('valid: someOtherFn(p, root); — unrelated callee name', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `someOtherFn(p, root);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
});
// ─── marker escape ────────────────────────────────────────────────────────────
describe('no-unconfined-path-join: marker escape', () => {
test('valid: suppressed with a real reason', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{
code: `resolved.startsWith(root + path.sep); // allow-handrolled-containment: legacy call site pending migration`,
filename: 'src/foo.cts',
},
],
invalid: [],
});
});
test('invalid: does NOT suppress with an empty reason', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep); // allow-handrolled-containment:`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: does NOT suppress without a colon', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep); // allow-handrolled-containment`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: does NOT suppress when the marker is on a different line', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `// allow-handrolled-containment: legacy call site pending migration\nresolved.startsWith(root + path.sep);`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('invalid: does NOT suppress with a BLOCK comment on the same line', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep); /* allow-handrolled-containment: legacy call site pending migration */`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('two violations on one line: trailing marker suppresses only the one it trails', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `a.startsWith(root + path.sep); b.startsWith(root + path.sep); // allow-handrolled-containment: legacy call site pending migration`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('valid: suppressed with a justification (b) reason — pre-build bootstrap file', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{
code: `resolved.startsWith(root + path.sep); // allow-handrolled-containment: this is a committed .cjs that must run before npm run build:lib, so src/security.cts is unreachable here`,
filename: 'gsd-core/bin/lib/capability-validator.cjs',
},
],
invalid: [],
});
});
test('valid: marker suppresses a discarded arm-2 call — tryWithinRoot(p, root); // allow-handrolled-containment: <reason>', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{
code: `tryWithinRoot(p, root); // allow-handrolled-containment: legacy call site pending migration`,
filename: 'src/foo.cts',
},
],
invalid: [],
});
});
test('invalid: the old spelling allow-lexical-prefix-match no longer suppresses', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep); // allow-lexical-prefix-match: legacy call site pending migration`,
filename: 'src/foo.cts',
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
});
// ─── allowlist ratchet ────────────────────────────────────────────────────────
describe('no-unconfined-path-join: allowlist', () => {
test('valid: allowlisted file with violations reports nothing', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{
code: `resolved.startsWith(root + path.sep);`,
filename: 'src/legacy.cts',
options: [{ allowlist: ['src/legacy.cts'] }],
},
],
invalid: [],
});
});
test('invalid: allowlisted file with ZERO violations reports staleAllowlistEntry', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `const x = 1;`,
filename: 'src/legacy.cts',
options: [{ allowlist: ['src/legacy.cts'] }],
errors: [{ messageId: 'staleAllowlistEntry' }],
},
],
});
});
test('invalid: allowlisted file whose only occurrence is marker-suppressed reports staleAllowlistEntry', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep); // allow-handrolled-containment: legacy call site pending migration`,
filename: 'src/legacy.cts',
options: [{ allowlist: ['src/legacy.cts'] }],
errors: [{ messageId: 'staleAllowlistEntry' }],
},
],
});
});
test('invalid: non-allowlisted file with violations reports', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [],
invalid: [
{
code: `resolved.startsWith(root + path.sep);`,
filename: 'src/other.cts',
options: [{ allowlist: ['src/legacy.cts'] }],
errors: [{ messageId: 'handRolledContainment' }],
},
],
});
});
test('valid: allowlisted file with one marked and one unmarked occurrence keeps the entry alive', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [
{
code: `a.startsWith(root + path.sep); // allow-handrolled-containment: legacy call site pending migration\nb.startsWith(root + path.sep);`,
filename: 'src/legacy.cts',
options: [{ allowlist: ['src/legacy.cts'] }],
},
],
invalid: [],
});
});
test('valid: rule configured with no options at all does not crash', () => {
ruleTester.run('no-unconfined-path-join', rule, {
valid: [{ code: `x.startsWith(prefix);`, filename: 'src/foo.cts' }],
invalid: [],
});
});
});