Skip to the content

Capsid menu

app/lib/admin/check-copy.mjs

171 lines and 18 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.

Functions

The functions of check-copy.mjs
FunctionLinesComplexityCoveredCRAPMutation
failing13 to 16250%OkCRAP 2.5No data: no mutants in this code
failing22 to 25250%OkCRAP 2.5No data: no mutants in this code
failing31 to 34250%OkCRAP 2.5No data: no mutants in this code
failing40 to 43250%OkCRAP 2.5No data: no mutants in this code
failing49 to 52250%OkCRAP 2.5No data: no mutants in this code
failing58 to 61250%OkCRAP 2.5No data: no mutants in this code
failing67 to 70250%OkCRAP 2.5No data: no mutants in this code
failing76 to 79250%OkCRAP 2.5No data: no mutants in this code
failing85 to 861100%OkCRAP 1No data: no mutants in this code
failing92 to 95250%OkCRAP 2.5No data: no mutants in this code
failing101 to 1021100%OkCRAP 1No data: no mutants in this code
failing108 to 111250%OkCRAP 2.5No data: no mutants in this code
failing117 to 120250%OkCRAP 2.5No data: no mutants in this code
failing127 to 1271100%OkCRAP 1No data: no mutants in this code
failing134 to 1341100%OkCRAP 1No data: no mutants in this code
humanCheck144 to 156477%OkCRAP 4.2No data: no mutants in this code
statusSentence162 to 17438%WatchCRAP 9.9No data: no mutants in this code
<anonymous:163>163 to 16310%OkCRAP 2No data: no mutants in this code

Imports

It imports no other module of this repo. Imported by app/routes/admin._index.tsx.

Source

/**
 * @typedef {object} CheckCopy
 * @property {string} name
 * @property {(counts: { expected: number, present: number } | undefined) => string | null} failing
 * @property {string} passing
 * @property {{ action: string, intent: string, label: string } | null} repair
 */

/** @type {Record<string, CheckCopy>} */
const CHECK_COPY = {
  "content-drift": {
    name: "Posts on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} posts are older on the site than in the repository. Syncing re-renders them.`
        : "Some posts are older on the site than in the repository. Syncing re-renders them.",
    passing: "Every post on the site matches the one in the repository.",
    repair: { action: "/admin/posts", intent: "regenerate", label: "Re-render every post" },
  },
  "procedures-drift": {
    name: "Procedures on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} procedures are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some procedures are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every procedure on the site matches the one in the repository.",
    repair: null,
  },
  "dictionary-drift": {
    name: "Dictionary entries on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} dictionary entries are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some dictionary entries are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every dictionary entry on the site matches the one in the repository.",
    repair: null,
  },
  "registry-drift": {
    name: "Lab registry on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} lab registry items are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some lab registry items are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every lab registry item on the site matches the one in the repository.",
    repair: null,
  },
  "pages-drift": {
    name: "Pages on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} pages are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some pages are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every page on the site matches the one in the repository.",
    repair: null,
  },
  "publications-drift": {
    name: "Publications on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} publications are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some publications are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every publication on the site matches the one in the repository.",
    repair: null,
  },
  "roster-drift": {
    name: "Roster on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} cohorts are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some cohorts are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every cohort on the site matches the one in the repository.",
    repair: null,
  },
  "phage-drift": {
    name: "Phage table on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} phages are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some phages are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "Every phage on the site matches the one in the repository.",
    repair: null,
  },
  "llms-drift": {
    name: "The llms.txt file on the site",
    failing: () =>
      "The llms.txt the site serves is older than the one in the repository. The site's watcher rewrites it on its next check.",
    passing: "The llms.txt the site serves matches the one in the repository.",
    repair: null,
  },
  "cv-drift": {
    name: "The CV on the site",
    failing: (counts) =>
      counts
        ? `${counts.expected - counts.present} of the ${counts.expected} CV files are older on the site than in the repository. The site's watcher re-compiles them on its next check.`
        : "Some CV files are older on the site than in the repository. The site's watcher re-compiles them on its next check.",
    passing: "The CV on the site matches the CV in the repository.",
    repair: null,
  },
  "cv-pdf-drift": {
    name: "The CV PDF",
    failing: () =>
      "The CV PDF is older than the CV on the site, or missing. The site's watcher re-renders it on its next check.",
    passing: "The CV PDF was drawn from the CV the site shows.",
    repair: null,
  },
  "ask-index-drift": {
    name: "Search answers",
    failing: (counts) =>
      counts
        ? `The answer index has ${counts.present} of ${counts.expected} posts, so an answer may quote text that has changed.`
        : "The answer index is out of step with the posts, so an answer may quote text that has changed.",
    passing: "The answer index has every post, and none it should not.",
    repair: { action: "/admin/posts", intent: "sync-ask", label: "Rebuild the answer index" },
  },
  "media-index-drift": {
    name: "Media library",
    failing: (counts) =>
      counts
        ? `The library lists ${counts.present} files and ${counts.expected} are stored, so something is missing from one side.`
        : "The library and the stored files disagree about what exists.",
    passing: "Every stored file is listed, and nothing is listed that is not there.",
    repair: { action: "/admin/media", intent: "rebuild", label: "Rebuild the library listing" },
  },
  "media-backup-drift": {
    name: "Media backups",
    // No counts: it compares key sets and etags, not totals, so the verdict's detail is used.
    failing: () => null,
    passing: "Every uploaded file has a second, byte-identical copy.",
    repair: null,
  },
  "fts-equality": {
    name: "Site search",
    // Same: five subqueries compared pairwise, not a total against a total.
    failing: () => null,
    passing: "Search knows about every post and every page it should.",
    repair: null,
  },
};

/**
 * @param {{ name: string, ok: boolean, detail: string, counts?: { expected: number, present: number } }} check
 * @returns {{ name: string, finding: string, repair: { action: string, intent: string, label: string } | null }}
 */
export function humanCheck(check) {
  const copy = CHECK_COPY[check.name];
  if (!copy) {
    // A check with no words yet still reads as words: "registry-drift" becomes "Registry drift".
    const words = check.name.replace(/-/g, " ");
    return { name: words.charAt(0).toUpperCase() + words.slice(1), finding: check.detail, repair: null };
  }
  if (check.ok) {
    return { name: copy.name, finding: copy.passing, repair: null };
  }
  const finding = copy.failing(check.counts) ?? check.detail;
  return { name: copy.name, finding, repair: copy.repair };
}

/**
 * @param {Array<{ name: string, ok: boolean, detail: string, counts?: { expected: number, present: number } }>} checks
 * @returns {string}
 */
export function statusSentence(checks) {
  const failing = checks.filter((check) => !check.ok);
  // Guard the value, not the length, so the compiler knows `worst` is defined.
  const worst = failing[0];
  if (!worst) {
    return "Everything agrees: the site, the repository, the library and search are all in step.";
  }
  const first = humanCheck(worst);
  if (failing.length === 1) {
    return `One thing needs attention. ${first.finding}`;
  }
  return `${failing.length} things need attention. ${first.finding}`;
}