Files
fleet/scripts/ci/experience-audit.test.mjs
CatoandClaude Sonnet 5.5 213d3f61b1 docs(experience): the experience belongs to the package, measured and enforced (#487)
* docs(experience): the experience belongs to the package, measured and enforced

The owner, 2026-11-06: every product installs the shared packages and the
screens people touch are still built per app — a text box with no microphone,
a header that is not ours, a comment list that works its own way. For a user
that is the same as no package at all. A non-technical person who says "make me
a website" must get the standard out of the door.

- AGENTS.md: "The experience belongs to the package". Packages ship behaviour
  and the layout skeleton; apps own words, backend and brand (tokens).
  Extending the package is the work, not a detour. A file that must be the
  exception says why on its first line.
- SHARED.md: "The experience standard" — what a person gets, from which
  package, measured per repo on 2026-11-06, how it is enforced.
- templates/agent-rules.md: one bullet, so the rule reaches every repo's
  AGENTS.md by the existing sync PRs and no future session can miss it.
- scripts/ci/experience-audit.mjs (+ tests): counts bare text areas, local
  chrome, composers, comment lists and article editors. package-composition
  runs it; a product whose package-plan.json sets experience.ceiling may not
  exceed it. The app template ships an empty ceiling, so a new product starts
  at zero.
- docs/experience-standard-plan.md: the living plan, status table and how to
  resume, for whoever picks this up next.
- shared-inventory.sh: its comment said UI markup was excluded so apps keep
  their own look; it now says behaviour is measured by the new audit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvpWNTLxXNfwUHS7MD

* docs(agents): regenerate the template rule blocks from templates/agent-rules.md

The audit job compares the three template AGENTS.md copies with the shipped
block; they had not been regenerated after the experience bullet was added.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmvpWNTLxXNfwUHS7MD

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-06 09:44:55 +01:00

77 lines
3.4 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { classify, measure, overCeiling } from './experience-audit.mjs';
const textarea = "export const A = () => <textarea />;";
test('a bare textarea counts; one beside chatkit or writingkit does not', () => {
assert.deepEqual(classify('src/Notes.tsx', textarea), ['bareTextareas']);
assert.deepEqual(
classify('src/Notes.tsx', "import { Composer } from '@bitbaum/chatkit/react';\n" + textarea),
[],
);
assert.deepEqual(
classify('src/Notes.tsx', "import { ArticleComposer } from '@bitbaum/writingkit/react';\n" + textarea),
[],
);
});
test('local chrome, composers, comments and article editors are named by their files', () => {
assert.deepEqual(classify('src/components/Header.tsx', 'export const H = () => null;'), ['localChrome']);
assert.deepEqual(
classify('src/components/Header.tsx', "import { SiteMasthead } from '@bitbaum/sitekit/react';"),
[],
);
assert.deepEqual(classify('src/ChatInput.tsx', 'export const C = () => null;'), ['localComposers']);
assert.deepEqual(classify('src/CommentList.tsx', 'export const C = () => null;'), ['localComments']);
assert.deepEqual(classify('src/ArticleComposer.tsx', 'export const C = () => null;'), ['localArticleEditors']);
assert.deepEqual(classify('src/Card.tsx', 'export const C = () => null;'), []);
});
test('an exemption needs a stated reason of at least 20 characters', () => {
assert.deepEqual(
classify('src/Notes.tsx', '// experience-exempt: a code editor, dictation would corrupt it\n' + textarea),
[],
);
assert.deepEqual(classify('src/Notes.tsx', '// experience-exempt: ok\n' + textarea), ['bareTextareas']);
assert.deepEqual(
classify('src/Notes.tsx', "'use client';\n// experience-exempt: a code editor, dictation would corrupt it\n" + textarea),
[],
);
});
test('measure skips tests, build output and dependencies', () => {
const dir = mkdtempSync(join(tmpdir(), 'experience-'));
try {
const put = (path, body) => {
mkdirSync(dirname(join(dir, path)), { recursive: true });
writeFileSync(join(dir, path), body);
};
put('src/Notes.tsx', textarea);
put('src/Notes.test.tsx', textarea);
put('node_modules/x/Notes.tsx', textarea);
put('.next/Notes.tsx', textarea);
put('__tests__/Notes.tsx', textarea);
put('src/components/Footer.tsx', 'export const F = () => null;');
const { counts, files } = measure(dir);
assert.equal(counts.bareTextareas, 1);
assert.equal(counts.localChrome, 1);
assert.deepEqual(files.bareTextareas, ['src/Notes.tsx']);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test('a ceiling holds the count; no ceiling only reports; a missing kind means zero', () => {
const counts = { bareTextareas: 3, localChrome: 1, localComposers: 0, localComments: 0, localArticleEditors: 0 };
assert.deepEqual(overCeiling(counts, {}), []);
assert.deepEqual(overCeiling(counts, { experience: { ceiling: { bareTextareas: 3, localChrome: 1 } } }), []);
const over = overCeiling(counts, { experience: { ceiling: { bareTextareas: 2 } } });
assert.equal(over.length, 2);
assert.match(over[0], /bareTextareas: 3 above the ceiling of 2/);
assert.match(over[1], /localChrome: 1 above the ceiling of 0/);
});