* feat(#2982): extend no-source-grep lint to catch var-binding readFileSync.includes() The base lint (scripts/lint-no-source-grep.cjs) only catches readFileSync(...).<text-method>() chained directly. The much more common var-binding form escapes it: const src = fs.readFileSync(p, 'utf8'); // 50 lines later if (src.includes('foo')) {} // ← still grep, lint missed it Scan of the test suite found ~141 files using this pattern. Implementation built TDD per #2982 with structured-IR assertions: scripts/lint-no-source-grep-extras.cjs - detectVarBindingViolations(src) — pure detector, two passes: pass 1 collects vars bound from readFileSync, pass 2 finds any <var>.<includes|startsWith|endsWith|match|search>( on those vars. - detectWrappedAssertOkMatch(src) — flags assert.ok(<expr>.match(...)) which escapes the assert.match rule. - VIOLATION enum exposes stable codes for tests to assert on. scripts/lint-no-source-grep.cjs - Wires the new detectors into the existing per-file check; one additional violation row per file with the first 3 sample tokens. tests/bug-2982-lint-var-binding.test.cjs - 13 tests, all assertions on typed VIOLATION enum / structured records. Covers all 5 text-match methods, multi-var, no-bind, string literal (must NOT trigger), wrapped assert.ok(.match), and assert.match (must NOT double-flag). Migration backlog (#2974 expanded scope): - 42 files annotated `// allow-test-rule: source-text-is-the-product` (legitimate — they read .md/.json/.yml files whose deployed text IS the product) - 3 files annotated `// allow-test-rule: pending-migration-to-typed-ir [#2974]` (read .cjs/.js source — clear migration debt) - 95 files annotated `pending-migration-to-typed-ir [#2974]` with `Per-file review may reclassify as source-text-is-the-product during migration` (mixed — manual review under #2974) After this lands the lint reports 0 violations on main; new violations in PRs surface immediately. Closes #2982 Refs #2974 * test(#2982): fix truncated test name per CR The label ended with a bare '(' from a copy-paste mishap. Now reads 'does NOT flag .matchAll(...) — matchAll is not match, so assert.ok(.matchAll(...)) is not flagged'. * chore(#2982): add changeset fragment for PR #2985 * chore(#2982): add changeset fragment for PR #2985
132 lines
4.8 KiB
JavaScript
132 lines
4.8 KiB
JavaScript
'use strict';
|
|
|
|
// allow-test-rule: pending-migration-to-typed-ir [#2974]
|
|
// Tracked in #2974 for migration to typed-IR assertions per CONTRIBUTING.md
|
|
// "Prohibited: Raw Text Matching on Test Outputs". Per-file review may
|
|
// reclassify some entries as source-text-is-the-product during migration.
|
|
|
|
/**
|
|
* iOS Scaffold Safety Tests (#2023)
|
|
*
|
|
* Validates that GSD guidance:
|
|
* 1. Does NOT instruct using Package.swift + .executableTarget as the primary
|
|
* build system for iOS apps (which produces a macOS CLI, not an iOS app).
|
|
* 2. DOES contain XcodeGen guidance (project.yml + xcodegen generate) for iOS
|
|
* app scaffolding.
|
|
* 3. Documents SwiftUI API availability (iOS 16 vs 17 compatibility).
|
|
*/
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const IOS_SCAFFOLD_REF = path.join(
|
|
__dirname, '..', 'get-shit-done', 'references', 'ios-scaffold.md'
|
|
);
|
|
const EXECUTOR_AGENT = path.join(
|
|
__dirname, '..', 'agents', 'gsd-executor.md'
|
|
);
|
|
const UNIVERSAL_ANTI_PATTERNS = path.join(
|
|
__dirname, '..', 'get-shit-done', 'references', 'universal-anti-patterns.md'
|
|
);
|
|
|
|
describe('ios-scaffold.md reference exists and contains XcodeGen guidance', () => {
|
|
test('reference file exists at get-shit-done/references/ios-scaffold.md', () => {
|
|
assert.ok(
|
|
fs.existsSync(IOS_SCAFFOLD_REF),
|
|
`Expected iOS scaffold reference at ${IOS_SCAFFOLD_REF}`
|
|
);
|
|
});
|
|
|
|
test('reference prohibits Package.swift as primary build system for iOS apps', () => {
|
|
const content = fs.readFileSync(IOS_SCAFFOLD_REF, 'utf-8');
|
|
const prohibitsPackageSwift =
|
|
content.includes('Package.swift') &&
|
|
(
|
|
content.includes('NEVER') ||
|
|
content.includes('never') ||
|
|
content.includes('prohibited') ||
|
|
content.includes('do not') ||
|
|
content.includes('Do not') ||
|
|
content.includes('must not')
|
|
);
|
|
assert.ok(
|
|
prohibitsPackageSwift,
|
|
'ios-scaffold.md must explicitly prohibit Package.swift as the primary build system for iOS apps'
|
|
);
|
|
});
|
|
|
|
test('reference prohibits .executableTarget for iOS apps', () => {
|
|
const content = fs.readFileSync(IOS_SCAFFOLD_REF, 'utf-8');
|
|
const prohibitsExecutableTarget =
|
|
content.includes('executableTarget') &&
|
|
(
|
|
content.includes('NEVER') ||
|
|
content.includes('never') ||
|
|
content.includes('prohibited') ||
|
|
content.includes('do not') ||
|
|
content.includes('Do not') ||
|
|
content.includes('must not')
|
|
);
|
|
assert.ok(
|
|
prohibitsExecutableTarget,
|
|
'ios-scaffold.md must explicitly prohibit .executableTarget for iOS app targets'
|
|
);
|
|
});
|
|
|
|
test('reference requires project.yml (XcodeGen spec) for iOS app scaffolding', () => {
|
|
const content = fs.readFileSync(IOS_SCAFFOLD_REF, 'utf-8');
|
|
assert.ok(
|
|
content.includes('project.yml'),
|
|
'ios-scaffold.md must require project.yml as the XcodeGen spec file'
|
|
);
|
|
});
|
|
|
|
test('reference requires xcodegen generate command', () => {
|
|
const content = fs.readFileSync(IOS_SCAFFOLD_REF, 'utf-8');
|
|
assert.ok(
|
|
content.includes('xcodegen generate') || content.includes('xcodegen'),
|
|
'ios-scaffold.md must require the xcodegen generate command to create .xcodeproj'
|
|
);
|
|
});
|
|
|
|
test('reference documents iOS deployment target compatibility', () => {
|
|
const content = fs.readFileSync(IOS_SCAFFOLD_REF, 'utf-8');
|
|
const hasApiCompatibility =
|
|
content.includes('iOS 16') ||
|
|
content.includes('iOS 17') ||
|
|
content.includes('deployment target') ||
|
|
content.includes('NavigationSplitView') ||
|
|
content.includes('availability') ||
|
|
content.includes('SwiftUI API');
|
|
assert.ok(
|
|
hasApiCompatibility,
|
|
'ios-scaffold.md must document SwiftUI API availability and iOS deployment target compatibility'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('gsd-executor.md references ios-scaffold guidance', () => {
|
|
test('executor agent references ios-scaffold.md', () => {
|
|
const content = fs.readFileSync(EXECUTOR_AGENT, 'utf-8');
|
|
assert.ok(
|
|
content.includes('ios-scaffold.md') || content.includes('ios-scaffold'),
|
|
'gsd-executor.md must reference ios-scaffold.md for iOS app scaffold guidance'
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('universal-anti-patterns.md documents iOS SPM anti-pattern', () => {
|
|
test('universal-anti-patterns.md documents Package.swift misuse for iOS apps', () => {
|
|
const content = fs.readFileSync(UNIVERSAL_ANTI_PATTERNS, 'utf-8');
|
|
const hasAntiPattern =
|
|
(content.includes('Package.swift') || content.includes('SPM')) &&
|
|
(content.includes('iOS') || content.includes('ios'));
|
|
assert.ok(
|
|
hasAntiPattern,
|
|
'universal-anti-patterns.md must document the Package.swift/SPM misuse anti-pattern for iOS apps'
|
|
);
|
|
});
|
|
});
|