Files
shared/scripts/media/enforce-no-skipped-tests.mjs
T
Gabriel20xxandClaude Sonnet 5 ee59571552 Rename ProjectConfigurator, restructure Projects workspace, retire MediaCollection naming
- Rename MediaConfig -> ProjectConfigurator throughout; drop the Parameters
  tab/page; rename the Mounts tab to Projects and restructure it into three
  sections: Central services, Main services, Third-party services
- Add a self-describe contract (GET /api/info returning name/tabs/mountTypes)
  and a server-side discovery proxy (POST /api/discover-service) so adding a
  main service only requires a URL
- Add ProjectConfigurator HA: multiple instances now sync their settings with
  each other (GET /api/settings/export, POST /api/settings/sync, a periodic
  background puller), last-write-wins per key by updated_at
- Add a generic, project-agnostic file-storage API on CarrierNode
  (GET/POST/DELETE /api/mount/{project}/{type}[/*]) driven by the same
  configured_mounts data the Projects workspace already writes, usable by any
  registered project, not just the media family
- Add last_login_at tracking to the shared auth Store/User (schema, queries,
  UpdateLastLogin) and surface it through the shared web-ui ManagedUser type
  and UserManagement component
- Retire the "MediaCollection" name: Go module -> repos.gfranz.ch/Gabriel20xx/shared/media-backend,
  binary -> mediabackend, session cookie default -> "session", media-webui
  merged into webui, media-shared-assets renamed to legacy-assets and pruned
  to the one file MediaDesktop still uses

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-04 15:02:16 +02:00

103 lines
3.3 KiB
JavaScript

#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(__dirname, '..', '..');
// The monorepo kept its canonical JS/TS test sources under a single repo-root tests/ dir, which
// doesn't exist in this repo. Scan the real locations JS/TS test files can currently live in
// this repo instead: webui/src (SvelteKit app) and shared/packages/*/test(s) (vendored from the
// shared repo). repoRoot/tests is kept as a forward-compatible root in case one is added later.
// As of this repo's extraction, none of these contain vitest/mocha/jest-style test files yet
// (shared/packages/node-backend/test/auth.test.js uses plain `node --test`, which shares the same
// describe/it/test .skip API surface these patterns already match), so this currently passes
// trivially rather than being a dead check.
const testsRoots = [
path.join(repoRoot, 'tests'),
path.join(repoRoot, 'webui', 'src'),
path.join(repoRoot, 'shared', 'packages'),
];
const TEST_FILE_EXTENSIONS = new Set(['.js', '.mjs', '.cjs']);
const DISALLOWED_LINE_PATTERNS = [
{
name: 'skip/todo/runIf declaration',
regex: /^\s*(?:await\s+)?(?:it|test|describe)\s*\.\s*(?:skip|todo|skipIf|runIf)\b/,
},
{
name: 'this.skip invocation',
regex: /\bthis\s*\.\s*skip\s*\(/,
},
];
const SKIP_DIR_NAMES = new Set(['node_modules', '.git', 'dist', 'build', '.svelte-kit']);
function listTestFiles(dir) {
if (!fs.existsSync(dir)) return [];
const out = [];
const stack = [dir];
while (stack.length) {
const current = stack.pop();
const entries = fs.readdirSync(current, { withFileTypes: true });
for (const entry of entries) {
const full = path.join(current, entry.name);
if (entry.isDirectory()) {
if (SKIP_DIR_NAMES.has(entry.name)) continue;
stack.push(full);
} else if (entry.isFile()) {
const ext = path.extname(entry.name).toLowerCase();
if (TEST_FILE_EXTENSIONS.has(ext)) {
out.push(full);
}
}
}
}
return out.sort();
}
function collectViolations(filePath) {
const src = fs.readFileSync(filePath, 'utf8');
const lines = src.split(/\r?\n/);
const violations = [];
for (let i = 0; i < lines.length; i += 1) {
const line = lines[i];
for (const pattern of DISALLOWED_LINE_PATTERNS) {
if (pattern.regex.test(line)) {
violations.push({
line: i + 1,
name: pattern.name,
text: line.trim(),
});
}
}
}
return violations;
}
const files = testsRoots.flatMap(listTestFiles).sort();
const failures = [];
for (const filePath of files) {
const violations = collectViolations(filePath);
if (violations.length) {
failures.push({ filePath, violations });
}
}
if (failures.length) {
console.error('[enforce-no-skipped-tests] Found disallowed skip-style test usage.');
for (const entry of failures) {
const rel = path.relative(repoRoot, entry.filePath).replace(/\\/g, '/');
for (const v of entry.violations) {
console.error(` - ${rel}:${v.line} (${v.name}) -> ${v.text}`);
}
}
process.exit(1);
}
console.log('[enforce-no-skipped-tests] OK: no skipped/pending test declarations found.');