Loading…
{:else if $metrics.isError} -Couldn't load metrics.
++ Couldn't load metrics. + +
{:else if $metrics.data && ($metrics.data.groups.length > 0 || $metrics.data.baseline)} {@const baseline = $metrics.data.baseline} {#if baseline} diff --git a/web/src/lib/testing/sourceGuard.ts b/web/src/lib/testing/sourceGuard.ts new file mode 100644 index 00000000..7550630a --- /dev/null +++ b/web/src/lib/testing/sourceGuard.ts @@ -0,0 +1,41 @@ +// Helpers for source guards: tests that read the web app's own source to +// assert a shape is absent (a hand-written count label, a native confirm()). +// Test-only; nothing in the app imports this. +import { readFileSync, readdirSync, statSync } from 'node:fs'; +import { dirname, join, relative } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +/** web/src. */ +export const SRC = join(dirname(fileURLToPath(import.meta.url)), '../..'); + +/** + * Comments describe the forbidden shape; strip them before asserting its + * absence, or the prose explaining a rule trips the check that enforces it. + */ +export const stripComments = (s: string): string => + s.replace(//g, '').replace(/^\s*\/\/.*$/gm, ''); + +/** Every .svelte and .ts file under web/src, tests left out. */ +export function appSources(dir: string = SRC): string[] { + return readdirSync(dir).flatMap((name) => { + const path = join(dir, name); + if (statSync(path).isDirectory()) return appSources(path); + return /\.(svelte|ts)$/.test(name) && !/\.test\.ts$/.test(name) ? [path] : []; + }); +} + +/** + * The app files, relative to web/src, whose source (comments stripped) + * matches any of patterns. Throws if the walk finds almost nothing, so a + * wrong root can't pass as "no offenders". + */ +export function offendingSources(patterns: RegExp[]): string[] { + const all = appSources(); + if (all.length < 100) throw new Error(`source guard found only ${all.length} files under ${SRC}`); + return all + .filter((path) => { + const text = stripComments(readFileSync(path, 'utf8')); + return patterns.some((re) => re.test(text)); + }) + .map((path) => relative(SRC, path)); +} diff --git a/web/src/lib/utils/plural.test.ts b/web/src/lib/utils/plural.test.ts index b5e66901..cd24de4f 100644 --- a/web/src/lib/utils/plural.test.ts +++ b/web/src/lib/utils/plural.test.ts @@ -1,8 +1,6 @@ -import { readFileSync, readdirSync, statSync } from 'node:fs'; -import { dirname, join, relative } from 'node:path'; -import { fileURLToPath } from 'node:url'; import { describe, expect, test } from 'vitest'; import { plural } from './plural.js'; +import { offendingSources } from '#lib/testing/sourceGuard.js'; describe('plural', () => { test('says a count with the noun that agrees with it', () => { @@ -21,8 +19,6 @@ describe('plural', () => { // - the suffix trick: `minute${n === 1 ? '' : 's'}`. // A choice of words with no count in it ("it" / "they", "yesterday") is // not a count label and stays a ternary. -const SRC = join(dirname(fileURLToPath(import.meta.url)), '../..'); - const HAND_ROLLED = [ /=== 1 \? ['"`]1 /, /\{([\w.]+)\}\s*\{\1 === 1 \?/, @@ -30,23 +26,8 @@ const HAND_ROLLED = [ /=== 1 \? '' : 's'/ ]; -/** Comments describe the forbidden shape; strip them before asserting its absence. */ -const stripComments = (s: string) => s.replace(//g, '').replace(/^\s*\/\/.*$/gm, ''); - -function sources(dir: string): string[] { - return readdirSync(dir).flatMap((name) => { - const path = join(dir, name); - if (statSync(path).isDirectory()) return sources(path); - return /\.(svelte|ts)$/.test(name) && !/\.test\.ts$/.test(name) ? [path] : []; - }); -} - describe('count labels', () => { test('every count in the web app is said by plural()', () => { - const offenders = sources(SRC).flatMap((path) => { - const text = stripComments(readFileSync(path, 'utf8')); - return HAND_ROLLED.some((re) => re.test(text)) ? [relative(SRC, path)] : []; - }); - expect(offenders).toEqual([]); + expect(offendingSources(HAND_ROLLED)).toEqual([]); }); }); diff --git a/web/src/routes/admin/users/+page.svelte b/web/src/routes/admin/users/+page.svelte index 14ba270f..019271e2 100644 --- a/web/src/routes/admin/users/+page.svelte +++ b/web/src/routes/admin/users/+page.svelte @@ -22,6 +22,7 @@ import { errCode, errMessage } from '#lib/api/errors.js'; import { pushToast } from '#lib/stores/toast.svelte.js'; import Modal from '#lib/components/Modal.svelte'; + import ConfirmModal from '#lib/components/ConfirmModal.svelte'; import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte'; import { Shield, ShieldOff, KeyRound, Trash2, Copy, Bug, BugOff } from 'lucide-svelte'; @@ -483,31 +484,15 @@ -- This permanently deletes the account and cascades through plays, likes, - sessions, and quarantine. The action cannot be undone. -
-- Forget {forgetting.label}, with their likes, plays and playlist places. A copy added later - comes in as a new track. -
-- Delete the file of {removeFileRow.title} and keep the track. - It waits in Needs a file, with its likes and plays, and takes over a good copy when one is in the - library. Its reports are cleared. -
-- Remove {deleteFileRow.title} and its file for good, with its - likes, plays and playlist places. Its reports and playback errors go with it. To keep the track for a - good copy, remove the file instead. -
-