Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(content-editor): hold the Quality score until the page's reads are in (#1470)

Cihanff0cb68a86b7
diff --git a/web/messages/en.json b/web/messages/en.json
index b5a0041ce..178402485 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -4326,6 +4326,8 @@
},
"qualityChip": "Quality {score}",
"qualityChipHint": "An Ansvisor estimate of this page's quality. Open Quality.",
+ "qualityChipReading": "Quality · reading…",
+ "qualityChipUpdating": "updating as the page is read",
"nextStep": {
"label": "Next step",
"short": "Next",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
index eda040891..11c0655ce 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_draft-editor.tsx
@@ -533,6 +533,8 @@ export function DraftEditor({
// Who the page is by (CE-038): page metadata, shown in the header and in a
// Page info strip outside the page; with Quality's first phase.
const [authorsRead, setAuthorsRead] = useState<AuthorsRead | null>(null);
+ // Read, or failed to: the header's score waits for it either way.
+ const [authorsTried, setAuthorsTried] = useState(false);
const [authorId, setAuthorId] = useState(draft.authorId);
// The author the database holds, and the latest pick: a slower pick that
// fails after a later one landed doesn't roll the menu back.
@@ -544,7 +546,8 @@ export function DraftEditor({
let live = true;
getContentAuthors()
.then((read) => live && setAuthorsRead(read))
- .catch((err) => console.error('Failed to load the authors:', err));
+ .catch((err) => console.error('Failed to load the authors:', err))
+ .finally(() => live && setAuthorsTried(true));
return () => {
live = false;
};
@@ -613,20 +616,18 @@ export function DraftEditor({
: [],
[sourcesOn, brandDomains, pageBlocks, competitorDomains, pageType, keptSources],
);
- const { kinds: aiKinds, paused: aiPaused } = useSourceClasses(
- draft.id,
- autosave.savedAt,
- unplaced,
- sourcesOn,
- );
+ const {
+ kinds: aiKinds,
+ paused: aiPaused,
+ reading: sourcesReading,
+ } = useSourceClasses(draft.id, autosave.savedAt, unplaced, sourcesOn);
+ // A save waiting or under way: the page's reads follow it. Not a failed
+ // save (or a conflict, a page too large): no new save is coming till it's fixed.
+ const saving = autosave.state === 'unsaved' || autosave.state === 'saving';
// The claims in the draft's own words, as the model reads them (CE-045):
// asked after a save, leaving the block the person is writing in.
- const claimsRead = useClaims(
- draft.id,
- autosave.savedAt,
- sourcesOn,
- autosave.state !== 'saved',
- () => (editor && !editor.isDestroyed && editor.isFocused ? writingBlock(editor) : null),
+ const claimsRead = useClaims(draft.id, autosave.savedAt, sourcesOn, saving, () =>
+ editor && !editor.isDestroyed && editor.isFocused ? writingBlock(editor) : null,
);
const { blocks: claimBlocks, recheck: recheckClaims } = claimsRead;
// Out of the editor (to Quality, to Before you publish): the block left
@@ -824,6 +825,29 @@ export function DraftEditor({
const { at: nudgeAt } = nudge;
// The author's to-dos wait for E-E-A-T: the nudge waits for them.
const todosRead = eeatScore !== null;
+ // The score the header and the panel show (CE-039): once the reads that
+ // move it are in, or failed (the authors and, in phase 2, Your input for
+ // E-E-A-T; the site's trust, the sources, the links and, in phase 2, the
+ // claims and the sites' kinds for Trust). Until the first time it says
+ // it's reading; after, it keeps the last settled score while new reads
+ // land (a link added, the agent's page), so it never jumps through the
+ // partial averages on the way.
+ const qualitySettled =
+ qualityOn &&
+ authorsTried &&
+ !inputsPending &&
+ siteTrustRead &&
+ reads.sources !== null &&
+ linksPending === 0 &&
+ !claimsRead.reading &&
+ !sourcesReading &&
+ // Phase 2 reads the page as saved: an edit's score waits for its save.
+ !(sourcesOn && saving);
+ const [shownQuality, setShownQuality] = useState<{ score: number | null } | null>(null);
+ if (qualitySettled && shownQuality?.score !== qualityScore) {
+ setShownQuality({ score: qualityScore });
+ }
+ const shownScore = shownQuality?.score ?? null;
const agentNudged = useRef(false);
useEffect(() => {
if (!agentFinished || !todosRead || agentNudged.current) return;
@@ -2443,21 +2467,43 @@ export function DraftEditor({
<span aria-hidden className="h-1.5 w-1.5 rounded-full bg-current" />
{t('rulesChip', { met: rules.met, total: rules.total })}
</button>
- {qualityScore !== null && (
+ {qualityOn && shownQuality === null && (
+ <button
+ type="button"
+ onClick={() => openPanelTab('quality')}
+ title={t('qualityChipHint')}
+ className="inline-flex h-5 shrink-0 items-center gap-1.5 rounded-full border bg-muted/40 px-2 text-xs font-medium text-muted-foreground"
+ >
+ <span
+ aria-hidden
+ className="h-1.5 w-1.5 animate-pulse rounded-full bg-current motion-reduce:animate-none"
+ />
+ {t('qualityChipReading')}
+ </button>
+ )}
+ {shownScore !== null && (
<button
type="button"
onClick={() => openPanelTab('quality')}
title={t('qualityChipHint')}
className={cn(
'inline-flex h-5 shrink-0 items-center gap-1.5 rounded-full border px-2 text-xs font-medium tabular-nums',
- BAND_CLASSES[qualityBand(qualityScore)],
+ BAND_CLASSES[qualityBand(shownScore)],
)}
>
- <span aria-hidden className="h-1.5 w-1.5 rounded-full bg-current" />
- {t('qualityChip', { score: qualityScore })}
+ <span
+ aria-hidden
+ className={cn(
+ 'h-1.5 w-1.5 rounded-full bg-current',
+ // New reads landing: the score may move once they're in.
+ !qualitySettled && 'animate-pulse motion-reduce:animate-none',
+ )}
+ />
+ {t('qualityChip', { score: shownScore })}
<span className="sr-only">
{' · '}
- {t(`quality.bands.${qualityBand(qualityScore)}`)}
+ {t(`quality.bands.${qualityBand(shownScore)}`)}
+ {!qualitySettled && ` · ${t('qualityChipUpdating')}`}
</span>
</button>
)}
@@ -2679,7 +2725,7 @@ export function DraftEditor({
briefRebuilding ? null : (aiUsedUp ?? (agentBusy ? t('suggestions.agentBusy') : null))
}
quality={quality}
- qualityScore={qualityScore}
+ qualityScore={shownScore}
onShowInPage={showInPage}
onShowPlaceholder={showFirstPlaceholder}
onPickAuthor={() => setAuthorMenuOpen(true)}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx
index c5e3ffa32..b4bb2f8cc 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.test.tsx
@@ -95,6 +95,20 @@ describe('useClaims', () => {
expect(checkDraftClaims).toHaveBeenCalledTimes(2);
});
+ it('is reading a save until its claims are asked about', async () => {
+ await render('s1');
+ await wait(CLAIMS_DELAY_MS);
+ expect(attr('data-reading')).toBe('false');
+ // A new save within the half minute: still to be read, the score may move.
+ await render('s2');
+ await wait(CLAIMS_DELAY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(1);
+ expect(attr('data-reading')).toBe('true');
+ await wait(CLAIMS_EVERY_MS);
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ expect(attr('data-reading')).toBe('false');
+ });
+
it('asks about a save made while an ask is out once it is back', async () => {
let answer: (value: unknown) => void = () => {};
checkDraftClaims.mockReturnValueOnce(new Promise((resolve) => (answer = resolve)));
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts
index 0ebb9f261..5ef39f0e7 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-claims.ts
@@ -30,9 +30,10 @@ export interface ClaimsRead {
* The claims in the draft's own words (Quality CE-045). The API reads the
* draft as saved and keeps each block's read, so the editor asks a few
* seconds after a save, CLAIMS_EVERY_MS apart at most, one ask at a time,
- * and not while there are changes to save (the API would read the page
- * before them). It leaves the block the person is writing in (`writingIn`,
- * read when it asks; null when they aren't), and asks again for one left,
+ * and not while a save is waiting or under way (the API would read the page
+ * before it; a failed save isn't one, the page as last saved is read). It
+ * leaves the block the person is writing in (`writingIn`, read when it
+ * asks; null when they aren't), and asks again for one left,
* or for blocks an ask had no calls left for, without waiting for a save.
* A spent AI budget or the day's reads made stop the asks for the session;
* an API with them off stops them silently; a failed ask waits for the next
@@ -51,6 +52,8 @@ export function useClaims(
const [off, setOff] = useState(false);
const [out, setOut] = useState(false);
const [pending, setPending] = useState(0);
+ // The save the last ask went out for: a later one is still to be read.
+ const [askedSave, setAskedSave] = useState<string | null>(null);
// Bumped when the next ask needn't wait for a save: one is out, or
// something was left for later.
const [again, setAgain] = useState(0);
@@ -85,6 +88,7 @@ export function useClaims(
const skip = reader.current();
asking.current = true;
askedFor.current = savedAt;
+ setAskedSave(savedAt);
lastAsk.current = Date.now();
skipped.current = skip;
left.current = false;
@@ -108,7 +112,9 @@ export function useClaims(
})
.catch((err) => {
console.error('Failed to read the claims:', err);
- if (open.current) setBlocks((prev) => prev ?? []);
+ if (!open.current) return;
+ setBlocks((prev) => prev ?? []);
+ setPending(0);
})
.finally(() => {
asking.current = false;
@@ -128,6 +134,12 @@ export function useClaims(
if (!asking.current) setAgain((n) => n + 1);
}, []);
- const reading = enabled && !paused && !limited && !off && (blocks === null || out || pending > 0);
+ // A save not asked about yet counts: its claims may move Trust once read.
+ const reading =
+ enabled &&
+ !paused &&
+ !limited &&
+ !off &&
+ (blocks === null || out || pending > 0 || askedSave !== savedAt);
return { blocks, paused, limited, reading, recheck };
}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.test.tsx
index 31cfba60e..27b8d5c35 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.test.tsx
@@ -85,13 +85,14 @@ describe('useLinkChecks', () => {
expect(checkDraftLinks).toHaveBeenCalledTimes(1);
});
- it('asks about a link not saved yet again after the next save', async () => {
+ it('asks about a link the answer left out again after the next save, not holding this one', async () => {
+ // Not saved yet (or over the hourly reads): the API's answer leaves it out.
saved = ['https://a.example/'];
await render(['https://a.example/', 'https://new.example/']);
await wait();
expect(seen().has('https://new.example/')).toBe(false);
- // Its read comes after the next save.
- expect(pending()).toBe(1);
+ // No read is coming at this save: it doesn't hold the score.
+ expect(pending()).toBe(0);
// Same save: not asked again.
await render(['https://a.example/', 'https://new.example/', 'https://a.example/']);
@@ -100,11 +101,38 @@ describe('useLinkChecks', () => {
saved = ['https://a.example/', 'https://new.example/'];
await render(['https://a.example/', 'https://new.example/'], 's2');
+ // Its read comes after the next save.
+ expect(pending()).toBe(1);
await wait();
expect(checkDraftLinks).toHaveBeenCalledTimes(2);
+ expect(pending()).toBe(0);
expect(seen().get('https://new.example/')?.status).toBe('ok');
});
+ it("doesn't let an older save's late answer hold a newer save's left-out link", async () => {
+ let lateA!: (answer: unknown) => void;
+ checkDraftLinks.mockImplementationOnce(() => new Promise((resolve) => (lateA = resolve)));
+ await render(['https://a.example/']);
+ await wait();
+ // A newer save asks again; its answer leaves the link out (over the hourly reads).
+ await render(['https://a.example/'], 's2');
+ await wait();
+ expect(checkDraftLinks).toHaveBeenCalledTimes(2);
+ expect(pending()).toBe(0);
+ await act(async () => lateA({ links: [], skipped: [] }));
+ expect(pending()).toBe(0);
+ });
+
+ it('counts a call that fails on its own as a failed read: no read is coming in this save', async () => {
+ vi.spyOn(console, 'error').mockImplementation(() => {});
+ checkDraftLinks.mockRejectedValueOnce(new Error('offline'));
+ await render(['https://a.example/']);
+ expect(pending()).toBe(1);
+ await wait();
+ expect(pending()).toBe(0);
+ vi.mocked(console.error).mockRestore();
+ });
+
it("doesn't ask again in the same save after a failed ask, nor with Quality off", async () => {
checkDraftLinks.mockResolvedValue({ error: 'failed' });
vi.spyOn(console, 'error').mockImplementation(() => {});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.ts
index 29408af98..f5516db92 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.ts
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-link-checks.ts
@@ -18,7 +18,8 @@ export const LINK_CHECK_DELAY_MS = 3_000;
* The links are compared as the draft saves them (cleanHref). `pending`
* counts the links whose read may still come (Before you publish says
* Trust may change): not read, not one the API never reads, and not asked
- * about at this save without an answer.
+ * about at this save without a read (a failed ask, or an answer that left
+ * it out: over the hourly reads, or written differently on the saved page).
*
* @param hrefs the page's http(s) links now, as it has them
* @param savedAt when the page was last saved
@@ -30,7 +31,8 @@ export function useLinkChecks(
enabled: boolean,
): { checks: Map<string, LinkCheck>; pending: number } {
const [checks, setChecks] = useState<Map<string, LinkCheck>>(() => new Map());
- // Links the API never reads, and the save each link's ask failed at.
+ // Links the API never reads, and the save each link's ask failed at or
+ // was answered without it.
const [skipped, setSkipped] = useState<ReadonlySet<string>>(() => new Set());
const [failedAt, setFailedAt] = useState<ReadonlyMap<string, string>>(() => new Map());
// The links read, and the save each other link was last asked about at.
@@ -54,26 +56,38 @@ export function useLinkChecks(
if (!fresh.length) return;
const timer = setTimeout(() => {
for (const href of fresh) askedAt.current.set(href, savedAt);
- void checkDraftLinks(draftId).then((result) => {
- if ('error' in result) {
- console.error('Failed to check the draft links:', result.error);
- if (open.current) {
- setFailedAt((prev) => new Map([...prev, ...fresh.map((h) => [h, savedAt] as const)]));
+ // Only the links this ask is still the last one about: an older ask
+ // answering late doesn't undo a newer save's.
+ const failed = (hrefs: string[]) => {
+ const own = hrefs.filter((h) => askedAt.current.get(h) === savedAt);
+ setFailedAt((prev) => new Map([...prev, ...own.map((h) => [h, savedAt] as const)]));
+ };
+ void checkDraftLinks(draftId)
+ .then((result) => {
+ if ('error' in result) {
+ console.error('Failed to check the draft links:', result.error);
+ if (open.current) failed(fresh);
+ return;
}
- return;
- }
- if (!open.current) return;
- if (result.skipped.length) setSkipped((prev) => new Set([...prev, ...result.skipped]));
- // A link the API never reads is as good as read: it isn't asked about again.
- for (const href of [...result.links.map((l) => l.href), ...result.skipped]) {
- read.current.add(href);
- }
- setChecks((prev) => {
- const next = new Map(prev);
- for (const link of result.links) next.set(link.href, link);
- return next;
+ if (!open.current) return;
+ if (result.skipped.length) setSkipped((prev) => new Set([...prev, ...result.skipped]));
+ // A link the API never reads is as good as read: it isn't asked about again.
+ const answered = new Set([...result.links.map((l) => l.href), ...result.skipped]);
+ for (const href of answered) read.current.add(href);
+ // One the answer left out has no read coming at this save either.
+ const missed = fresh.filter((href) => !answered.has(href));
+ if (missed.length) failed(missed);
+ setChecks((prev) => {
+ const next = new Map(prev);
+ for (const link of result.links) next.set(link.href, link);
+ return next;
+ });
+ })
+ // The call failing on its own (the network, a deploy meanwhile): as a failed read.
+ .catch((err) => {
+ console.error('Failed to check the draft links:', err);
+ if (open.current) failed(fresh);
});
- });
}, LINK_CHECK_DELAY_MS);
return () => clearTimeout(timer);
}, [draftId, savedAt, key, enabled]);
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.test.tsx
index 72b0934fc..f5faf43c8 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.test.tsx
@@ -8,6 +8,7 @@ vi.mock('@/lib/actions/content-drafts', () => ({
}));
const { SOURCE_CLASS_DELAY_MS, useSourceClasses } = await import('./_use-source-classes');
+const { MAX_SOURCE_SITES } = await import('@/lib/content/source-class');
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =
true;
@@ -30,8 +31,14 @@ function Probe({
savedAt: string;
enabled: boolean;
}) {
- const { kinds, paused } = useSourceClasses('d1', savedAt, sites, enabled);
- return <pre data-kinds={JSON.stringify([...kinds])} data-paused={String(paused)} />;
+ const { kinds, paused, reading } = useSourceClasses('d1', savedAt, sites, enabled);
+ return (
+ <pre
+ data-kinds={JSON.stringify([...kinds])}
+ data-paused={String(paused)}
+ data-reading={String(reading)}
+ />
+ );
}
const kinds = () =>
@@ -55,7 +62,26 @@ afterEach(() => {
vi.useRealTimers();
});
+const reading = () => container.querySelector('pre')?.getAttribute('data-reading') === 'true';
+
describe('useSourceClasses', () => {
+ it('is reading a site until it has its kind, or its ask at this save is answered', async () => {
+ await render(['blog.example']);
+ expect(reading()).toBe(true);
+ await wait();
+ expect(reading()).toBe(false);
+ // An ask that fails: read again after the next save, not reading meanwhile.
+ vi.spyOn(console, 'error').mockImplementation(() => {});
+ classifyDraftSources.mockRejectedValueOnce(new Error('offline'));
+ await render(['blog.example', 'forum.example']);
+ expect(reading()).toBe(true);
+ await wait();
+ expect(reading()).toBe(false);
+ await render(['blog.example', 'forum.example'], 's2');
+ expect(reading()).toBe(true);
+ vi.mocked(console.error).mockRestore();
+ });
+
it('asks about the sites a few seconds after a save, and keeps each read', async () => {
await render(['blog.example']);
await wait(SOURCE_CLASS_DELAY_MS - 100);
@@ -110,6 +136,22 @@ describe('useSourceClasses', () => {
error.mockRestore();
});
+ it('asks about the sites past a failed batch at the same save', async () => {
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
+ classifyDraftSources.mockRejectedValueOnce(new Error('network'));
+ const sites = Array.from({ length: MAX_SOURCE_SITES + 1 }, (_, i) => `site${i}.example`);
+ await render(sites);
+ await wait();
+ expect(classifyDraftSources).toHaveBeenCalledTimes(1);
+ // The one past the batch is still to be read: asked without a save.
+ expect(reading()).toBe(true);
+ await wait();
+ expect(classifyDraftSources).toHaveBeenCalledTimes(2);
+ expect(classifyDraftSources).toHaveBeenLastCalledWith('d1', [sites[MAX_SOURCE_SITES]]);
+ expect(reading()).toBe(false);
+ error.mockRestore();
+ });
+
it('stops asking, silently, when the API has the reads off', async () => {
classifyDraftSources.mockResolvedValueOnce({ error: 'off' });
await render(['blog.example']);
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.ts b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.ts
index f663a3cac..477df7bd3 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.ts
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/_use-source-classes.ts
@@ -25,11 +25,13 @@ export function useSourceClasses(
savedAt: string,
sites: string[],
enabled: boolean,
-): { kinds: ReadonlyMap<string, AiSourceClass>; paused: boolean } {
+): { kinds: ReadonlyMap<string, AiSourceClass>; paused: boolean; reading: boolean } {
const [kinds, setKinds] = useState<ReadonlyMap<string, AiSourceClass>>(() => new Map());
const [paused, setPaused] = useState(false);
// The API has them off (its Quality phase under 2): nothing to ask.
const [off, setOff] = useState(false);
+ // Each site's last answer (or failure), by the save it was asked at.
+ const [answered, setAnswered] = useState<ReadonlyMap<string, string>>(() => new Map());
const askedAt = useRef(new Map<string, string>());
// Sites an ask is out for: a save meanwhile doesn't ask about them again.
const asking = useRef(new Set<string>());
@@ -81,10 +83,23 @@ export function useSourceClasses(
.catch((err) => console.error('Failed to read the sources:', err))
.finally(() => {
for (const site of fresh) asking.current.delete(site);
+ if (open.current) {
+ setAnswered(
+ (prev) => new Map([...prev, ...fresh.map((site) => [site, savedAt] as const)]),
+ );
+ }
});
}, SOURCE_CLASS_DELAY_MS);
return () => clearTimeout(timer);
- }, [draftId, savedAt, key, enabled, paused, off, kinds]);
+ // Each answer (a failed one too) lets the sites past the batch, or held
+ // while their ask was out, be asked at this save.
+ }, [draftId, savedAt, key, enabled, paused, off, kinds, answered]);
- return { kinds, paused };
+ // A site with no read and none answered at this save is still to be read.
+ const reading =
+ enabled &&
+ !paused &&
+ !off &&
+ sites.some((site) => site && !kinds.has(site) && answered.get(site) !== savedAt);
+ return { kinds, paused, reading };
}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
index 0b9d46347..e24685c34 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx
@@ -9,6 +9,7 @@ import type { ContentDraft } from '@/lib/content/drafts';
import type { DraftSuggestion } from '@/lib/content/suggestions';
import { passageKey, type CitedPassage } from '@/lib/content/cited-passages';
import { encodeHtmlBlock } from '@/lib/content/html-allowlist';
+import { CLAIMS_EVERY_MS } from './_use-claims';
import ContentEditorPage from './page';
const getContentDraft = vi.fn();
@@ -2478,6 +2479,49 @@ describe('the side panel', () => {
expect(panel()!.textContent).toContain('Not a Google score.');
});
+ it('says it is reading until the page’s reads are in, then shows one score, not the partial ones', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '1';
+ let authorsIn!: (read: unknown) => void;
+ getContentAuthors.mockReturnValue(new Promise((resolve) => (authorsIn = resolve)));
+ getContentDraft.mockResolvedValue(readable);
+ window.innerWidth = 1440;
+ await renderPage();
+ const chip = () =>
+ [...container.querySelectorAll<HTMLButtonElement>('header button')].find((b) =>
+ b.textContent?.startsWith('Quality'),
+ );
+ // Readability alone would say more than the page is worth: no number yet.
+ expect(chip()?.textContent).toBe('Quality · reading…');
+ await act(async () =>
+ authorsIn({
+ authors: [],
+ brands: [{ id: 'b1', name: 'Acme' }],
+ me: { id: 'u1', role: 'admin' },
+ }),
+ );
+ expect(chip()?.textContent).toMatch(/^Quality \d+ · (Strong|Can improve|Needs work)$/);
+ const score = chip()!.textContent!.match(/\d+/)![0];
+ await act(async () => chip()!.click());
+ expect(selectedSegment()).toContain(`Quality${score}`);
+ });
+
+ it('shows the score once the authors fail to load too', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '1';
+ vi.spyOn(console, 'error').mockImplementation(() => {});
+ try {
+ getContentAuthors.mockRejectedValue(new Error('offline'));
+ getContentDraft.mockResolvedValue(readable);
+ window.innerWidth = 1440;
+ await renderPage();
+ const chip = [...container.querySelectorAll<HTMLButtonElement>('header button')].find((b) =>
+ b.textContent?.startsWith('Quality'),
+ );
+ expect(chip?.textContent).toMatch(/^Quality \d+/);
+ } finally {
+ vi.mocked(console.error).mockRestore();
+ }
+ });
+
it("asks for Your input in its second phase, and Add opens it at Brief's top (CE-048)", async () => {
process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
getContentAuthors.mockResolvedValue({
@@ -2540,6 +2584,7 @@ describe('the side panel', () => {
it('scores without Your input when it can’t be read, and Brief offers to read it again', async () => {
process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
vi.spyOn(console, 'error').mockImplementation(() => {});
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
try {
getContentAuthors.mockResolvedValue({
authors: [],
@@ -2550,6 +2595,9 @@ describe('the side panel', () => {
getContentDraft.mockResolvedValue(readable);
window.innerWidth = 1440;
await renderPage();
+ // The claims are read after a save's pause: no score until they are.
+ expect(qualityChip()?.textContent).toBe('Quality · reading…');
+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));
expect(qualityChip()?.textContent).toMatch(/^Quality \d+/);
await pickTab('Brief');
const retry = [...panel()!.querySelectorAll('button')].find(
@@ -2561,6 +2609,48 @@ describe('the side panel', () => {
expect(panel()!.querySelector('#your-experience')).not.toBeNull();
} finally {
vi.mocked(console.error).mockRestore();
+ vi.useRealTimers();
+ }
+ });
+
+ it('holds the score while an edit waits for its save: phase 2 reads the page as saved', async () => {
+ process.env.NEXT_PUBLIC_CONTENT_QUALITY_PHASE = '2';
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ try {
+ getContentAuthors.mockResolvedValue({
+ authors: [],
+ brands: [{ id: 'b1', name: 'Acme' }],
+ me: { id: 'u1', role: 'admin' },
+ });
+ getContentDraft.mockResolvedValue(readable);
+ saveContentDraft.mockResolvedValue({
+ ok: true,
+ updatedAt: '2026-10-20T10:01:00Z',
+ bodyHash: 'h1',
+ });
+ window.innerWidth = 1440;
+ await renderPage();
+ await act(async () => void (await vi.advanceTimersByTimeAsync(3_000)));
+ expect(qualityChip()?.textContent).not.toContain('updating');
+ const editor = (container.querySelector('.ProseMirror') as HTMLElement & { editor: Editor })
+ .editor;
+ await act(async () => {
+ editor.commands.insertContentAt(
+ editor.state.doc.content.size,
+ '<p>Forecasts missed by less each quarter.</p>',
+ );
+ });
+ // Not saved yet: the claims read is the page's before the edit.
+ expect(qualityChip()?.textContent).toContain('updating as the page is read');
+ await act(async () => void (await vi.advanceTimersByTimeAsync(2_000)));
+ expect(saveContentDraft).toHaveBeenCalledTimes(1);
+ // Saved: the score waits for its claims, asked a few seconds later.
+ expect(qualityChip()?.textContent).toContain('updating as the page is read');
+ await act(async () => void (await vi.advanceTimersByTimeAsync(CLAIMS_EVERY_MS)));
+ expect(checkDraftClaims).toHaveBeenCalledTimes(2);
+ expect(qualityChip()?.textContent).not.toContain('updating');
+ } finally {
+ vi.useRealTimers();
}
});