Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(x-content): give X Articles their own every-other-day 22:30 slot and release reviewed Articles by policy

nirholas0841361f7746
diff --git a/api/_lib/x-content/approval.js b/api/_lib/x-content/approval.js
index 564514e4a..7877693ee 100644
--- a/api/_lib/x-content/approval.js
+++ b/api/_lib/x-content/approval.js
@@ -16,6 +16,16 @@
// decides that
// the review passed on the editor's own verdict, not on an override
//
+// An X Article has its own rule, `approval.articles` (owner, 2026-10-08: one
+// Article every two days, released without the owner). An Article is long-form
+// writing about how something works, so there is rarely a reel to film; what
+// stands in for the reel is the review itself, which re-ran every probe the
+// Article declares against production, resolved every link in it, and held
+// every sentence of its body to the claims ledger. With `articles` on, an
+// Article is not held back by its tier or by having no scenario, and every
+// other condition still applies, including a tag anywhere in the body. An
+// Article that does carry a scenario must still have a current proof.
+//
// A release by policy is never immediate. The post is embargoed for
// `vetoHours`, and the release is written to the ops alerts, so there is always
// a window in which `npm run x:content -- pause <id>` takes it back.
@@ -23,9 +33,11 @@
import { proofProblems } from './reel.js';
import { tierOf } from './schedule.js';
import { mentionsIn } from './editorial.js';
+import { existsSync, readFileSync } from 'node:fs';
+import { join } from 'node:path';
const HOUR = 3_600_000;
-export const DEFAULT_APPROVAL = { mode: 'owner', tiers: [2, 3], vetoHours: 24 };
+export const DEFAULT_APPROVAL = { mode: 'owner', tiers: [2, 3], vetoHours: 24, articles: false };
export const MIN_VETO_HOURS = 1;
export function approvalPolicy(queue) {
@@ -36,6 +48,7 @@ export function approvalPolicy(queue) {
mode: raw.mode === 'auto' ? 'auto' : 'owner',
tiers,
vetoHours: Number.isFinite(veto) && veto >= MIN_VETO_HOURS ? veto : DEFAULT_APPROVAL.vetoHours,
+ articles: raw.articles === true,
};
}
@@ -43,16 +56,22 @@ export function approvalPolicy(queue) {
export function policyBlockers(item, record, policy, root, now = Date.now()) {
if (policy.mode !== 'auto') return ['the queue leaves approval to the owner'];
const reasons = [];
- if (!policy.tiers.includes(tierOf(item))) reasons.push(`tier ${tierOf(item)} posts are approved by the owner`);
- if (!item.scenario) reasons.push('it was never filmed against the product');
- else reasons.push(...proofProblems(item, root, now).map((problem) => `proof: ${problem}`));
- const tagged = mentionsIn((item.posts || []).map((post) => post.text).join('\n'));
+ const article = item.kind === 'article' && policy.articles;
+ if (!article && !policy.tiers.includes(tierOf(item))) reasons.push(`tier ${tierOf(item)} posts are approved by the owner`);
+ if (item.scenario) reasons.push(...proofProblems(item, root, now).map((problem) => `proof: ${problem}`));
+ else if (!article) reasons.push('it was never filmed against the product');
+ const tagged = mentionsIn([...(item.posts || []).map((post) => post.text), ...(item.kind === 'article' ? [item.article?.title, articleBody(item, root)] : [])].filter(Boolean).join('\n'));
if (tagged.length) reasons.push(`it tags ${tagged.join(', ')}`);
if (!record?.passed) reasons.push('its review did not pass');
else if (record.editor?.verdict !== 'publish') reasons.push(`the editor's verdict was ${record.editor?.verdict || 'never given'}`);
return reasons;
}
+function articleBody(item, root) {
+ const path = item.article?.body && join(root, item.article.body);
+ return path && existsSync(path) ? readFileSync(path, 'utf8') : '';
+}
+
// The embargo a policy release carries: the later of the one the post already
// had and the end of the veto window.
export function vetoUntil(item, policy, now = Date.now()) {
diff --git a/api/_lib/x-content/runner.js b/api/_lib/x-content/runner.js
index 5f8f8ce45..7ac7588e7 100644
--- a/api/_lib/x-content/runner.js
+++ b/api/_lib/x-content/runner.js
@@ -14,7 +14,7 @@
// reads the timeline again if the stored record has gone stale.
import { loadQueue, validateQueue } from './queue.js';
-import { DEFAULT_CADENCE, SLOT_OPEN_MINUTES, TIERS, pickDue, slotOpenings, tierOf } from './schedule.js';
+import { DEFAULT_CADENCE, SLOT_OPEN_MINUTES, TIERS, isKindSlot, pickDue, reservedKinds, slotLabel, slotOpenings, tierOf } from './schedule.js';
import { loadLifts } from './priority.js';
import { loadReview, contentHash } from './review.js';
import { previewClient, publishItem, xClientFromEnv } from './publisher.js';
@@ -74,29 +74,39 @@ async function preflight(item, root) {
}
// ── Inventory ───────────────────────────────────────────────────────────────
-// Days of approved, ready stock per tier (one slot per tier per day). Anything
-// under INVENTORY_WARN_DAYS is raised once a day through the platform's ops
-// alerts, so the queue asks for more posts before it goes quiet, instead of
-// after.
+// Days of approved, ready stock per tier (one slot per tier per day), and per
+// kind slot (one item every `everyDays`). Anything under INVENTORY_WARN_DAYS is
+// raised once a day through the platform's ops alerts, so the queue asks for
+// more posts before it goes quiet, instead of after.
export const INVENTORY_WARN_DAYS = 3;
-export function inventory(items, state, root, now = Date.now()) {
+export function inventory(items, state, root, now = Date.now(), cadence = {}) {
const publishedIds = new Set((state.published || []).map((row) => row.id));
const held = activeHolds(state, items, root, now);
+ const reserved = reservedKinds(cadence);
const counts = new Map(TIERS.map((tier) => [tier, 0]));
+ const byKind = new Map([...reserved].map((kind) => [kind, 0]));
for (const item of items) {
if (item.status !== 'approved' || publishedIds.has(item.id) || held.has(item.id)) continue;
if (item.expiresAt && Date.parse(item.expiresAt) <= now) continue;
- counts.set(tierOf(item), counts.get(tierOf(item)) + 1);
+ if (reserved.has(item.kind)) byKind.set(item.kind, byKind.get(item.kind) + 1);
+ else counts.set(tierOf(item), counts.get(tierOf(item)) + 1);
}
- return TIERS.map((tier) => ({ tier, days: counts.get(tier), low: counts.get(tier) < INVENTORY_WARN_DAYS }));
+ const tiers = TIERS.map((tier) => ({ tier, days: counts.get(tier), low: counts.get(tier) < INVENTORY_WARN_DAYS }));
+ const kinds = (cadence.slots || []).filter(isKindSlot).map((slot) => {
+ const days = byKind.get(slot.kind) * Math.max(1, Math.floor(Number(slot.everyDays) || 1));
+ return { kind: slot.kind, count: byKind.get(slot.kind), days, low: days < INVENTORY_WARN_DAYS };
+ });
+ return [...tiers, ...kinds];
}
+export const stockLabel = (row) => (row.kind ? `${row.kind}: ${row.count} (${row.days} day(s))` : `T${row.tier}: ${row.days} day(s)`);
+
async function alertLowInventory(state, store, stock, now) {
const today = new Date(now).toISOString().slice(0, 10);
if (!stock.some((row) => row.low) || state.inventoryAlertedOn === today) return null;
const { sendOpsAlert } = await import('../alerts.js');
- const summary = stock.map((row) => `T${row.tier}: ${row.days} day(s)`).join(', ');
+ const summary = stock.map(stockLabel).join(', ');
await sendOpsAlert('x-content: approved post stock is low', `${summary}. Draft, review, and approve more posts: npm run x:content -- plan`);
state.inventoryAlertedOn = today;
await store.save(state);
@@ -171,7 +181,7 @@ async function alertEmptySlot(state, store, slot, reason) {
state.emptySlotAlerted[slot.key] = new Date().toISOString();
await store.save(state);
const { sendOpsAlert } = await import('../alerts.js');
- await sendOpsAlert(`x-content: slot ${slot.key} (T${slot.tier}) is open with nothing to post`, `${reason}. Approve or advance a post now: npm run x:content -- advance --ship`);
+ await sendOpsAlert(`x-content: slot ${slot.key} (${slotLabel(slot)}) is open with nothing to post`, `${reason}. Approve or advance a post now: npm run x:content -- advance --ship`);
}
export function missedSlots(state, cadence, seed, now = Date.now()) {
@@ -188,7 +198,7 @@ async function alertMissedSlots(state, store, cadence, seed, now) {
for (const slot of missed) state.missedSlots[slot.key] = new Date(now).toISOString();
await store.save(state);
const { sendOpsAlert } = await import('../alerts.js');
- await sendOpsAlert(`x-content: ${missed.length} slot(s) closed with no post`, missed.map((slot) => `${slot.key} (T${slot.tier})`).join(', '));
+ await sendOpsAlert(`x-content: ${missed.length} slot(s) closed with no post`, missed.map((slot) => `${slot.key} (${slotLabel(slot)})`).join(', '));
return missed.map((slot) => slot.key);
}
@@ -263,7 +273,7 @@ export async function runTick({
}
async function fillSlot({ queue, state, store, root, now, requestedId, client, checks, context, publishable, blocked }) {
- const stock = inventory(publishable, state, root, now);
+ const stock = inventory(publishable, state, root, now, queue.cadence || {});
const lowStock = requestedId ? null : await alertLowInventory(state, store, stock, now).catch(() => null);
const exclude = requestedId ? new Set() : activeHolds(state, publishable, root, now);
@@ -278,7 +288,7 @@ async function fillSlot({ queue, state, store, root, now, requestedId, client, c
const item = decision.item;
if (decision.vetoYielded) {
const { sendOpsAlert } = await import('../alerts.js');
- await sendOpsAlert(`x-content: ${item.id} goes out before its veto window ends`, `Slot ${decision.slot.key} (T${decision.slot.tier}) had nothing else ready. Its embargo ran until ${item.notBefore}.`, { severity: 'info' }).catch(() => {});
+ await sendOpsAlert(`x-content: ${item.id} goes out before its veto window ends`, `Slot ${decision.slot.key} (${slotLabel(decision.slot)}) had nothing else ready. Its embargo ran until ${item.notBefore}.`, { severity: 'info' }).catch(() => {});
}
// A resumed thread must finish what it started, so it skips pre-flight.
@@ -294,7 +304,7 @@ async function fillSlot({ queue, state, store, root, now, requestedId, client, c
}
try {
- const meta = decision.slot ? { slot: decision.slot.key, tier: decision.tier, slotTier: decision.slot.tier } : {};
+ const meta = decision.slot ? { slot: decision.slot.key, tier: decision.tier, slotTier: decision.slot.tier, ...(decision.slot.kind ? { slotKind: decision.slot.kind } : {}) } : {};
const row = await publishItem({ item, client, root, state, store, account: queue.account, meta, now });
if (state.holds?.[item.id]) {
delete state.holds[item.id];
diff --git a/api/_lib/x-content/schedule.js b/api/_lib/x-content/schedule.js
index b64d7a750..56c201cef 100644
--- a/api/_lib/x-content/schedule.js
+++ b/api/_lib/x-content/schedule.js
@@ -99,6 +99,28 @@ const atMinutes = (at) => {
// that, and `isWeekend` still answers the question it asks.
export const isWeekend = (timestamp) => [0, 6].includes(new Date(timestamp).getUTCDay());
+// ── Kind slots ──────────────────────────────────────────────────────────────
+// A slot may belong to a kind of item instead of a tier, and open every few
+// days instead of every day: `{ kind: 'article', at: '22:30', everyDays: 2,
+// from: '2026-10-08' }` is one X Article every second day (owner, 2026-10-08).
+// Items of a kind that owns a slot are kept for that slot, so the daily tiered
+// slots never spend an Article and the Article slot never spends a post. A kind
+// slot sits outside the daily cap: its own cadence already limits it, and a cap
+// shared with the three daily posts would let an Article evening hold the next
+// morning's slot shut. `from` is the first day the slot opens; it then opens on
+// every `everyDays`-th UTC day after it (and, by the same arithmetic, before).
+export const isKindSlot = (slot) => Boolean(slot?.kind);
+export const slotLabel = (slot) => (isKindSlot(slot) ? slot.kind : `T${slot.tier}`);
+export const reservedKinds = (cadence = {}) => new Set((cadence.slots || []).filter(isKindSlot).map((slot) => slot.kind));
+
+export function slotOpensOn(slot, day) {
+ const every = Math.max(1, Math.floor(Number(slot.everyDays) || 1));
+ if (every === 1) return true;
+ const from = slot.from ? Date.parse(`${slot.from}T00:00:00Z`) : 0;
+ const days = Math.round((Date.parse(`${dayKey(day)}T00:00:00Z`) - from) / DAY);
+ return ((days % every) + every) % every === 0;
+}
+
// Every slot opening from yesterday through tomorrow, in time order, so the
// slot spanning midnight (22:00 until the next morning) is found too.
export function slotOpenings(now, cadence = DEFAULT_CADENCE, seed = null) {
@@ -110,8 +132,10 @@ export function slotOpenings(now, cadence = DEFAULT_CADENCE, seed = null) {
const day = today + offset * DAY;
slots.forEach((slot, index) => {
if (cadence.flagshipWeekdaysOnly && Number(slot.tier) === 1 && isWeekend(day)) return;
+ if (!slotOpensOn(slot, day)) return;
const key = `${dayKey(day)}#${index}`;
- openings.push({ key, tier: Number(slot.tier), opensAt: day + (atMinutes(slot.at) + jitterMinutes(`slot:${key}`, window, seed)) * MINUTE });
+ const owner = isKindSlot(slot) ? { kind: String(slot.kind), tier: null } : { tier: Number(slot.tier) };
+ openings.push({ key, ...owner, opensAt: day + (atMinutes(slot.at) + jitterMinutes(`slot:${key}`, window, seed)) * MINUTE });
});
}
return openings.sort((a, b) => a.opensAt - b.opensAt);
@@ -186,7 +210,7 @@ export function pickDue({
const { slot, next } = currentSlot(now, cadence, seed);
const nextAt = next ? new Date(next.opensAt).toISOString() : 'tomorrow';
if (!slot) return { item: null, reason: `no slot is open; the next opens at ${nextAt}` };
- if (published.some((row) => row.slot === slot.key)) return { item: null, reason: `slot ${slot.key} (T${slot.tier}) is used; the next opens at ${nextAt}` };
+ if (published.some((row) => row.slot === slot.key)) return { item: null, reason: `slot ${slot.key} (${slotLabel(slot)}) is used; the next opens at ${nextAt}` };
const last = published[published.length - 1];
if (last && now < Date.parse(last.publishedAt) + cadence.minimumMinutesApart * MINUTE) {
@@ -200,25 +224,31 @@ export function pickDue({
// the schedule to one post each, and the spacing check above still measures
// from the last post of any kind, so a hand-sent post can never be followed by
// a scheduled one minutes later.
- const scheduledLastDay = published.filter((row) => row.slot && now - Date.parse(row.publishedAt) < DAY).length;
- if (scheduledLastDay >= cadence.dailyCap) return { item: null, reason: `daily cap of ${cadence.dailyCap} scheduled posts reached` };
+ // A kind slot (see above) is outside the cap, and its posts are not counted.
+ const scheduledLastDay = published.filter((row) => row.slot && !row.slotKind && now - Date.parse(row.publishedAt) < DAY).length;
+ if (!isKindSlot(slot) && scheduledLastDay >= cadence.dailyCap) return { item: null, reason: `daily cap of ${cadence.dailyCap} scheduled posts reached` };
// On a weekend a flagship post waits for Monday instead of filling a lower slot.
const holdFlagship = Boolean(cadence.flagshipWeekdaysOnly) && isWeekend(slot.opensAt);
- const candidates = unpublished.filter((item) => !exclude.has(item.id) && !(holdFlagship && tierOf(item) === 1));
+ // A kind slot takes only its kind; the tiered slots take everything a kind
+ // slot does not own.
+ const reserved = reservedKinds(cadence);
+ const fits = (item) => (isKindSlot(slot) ? item.kind === slot.kind : !reserved.has(item.kind));
+ const candidates = unpublished.filter((item) => fits(item) && !exclude.has(item.id) && !(holdFlagship && tierOf(item) === 1));
const ready = candidates.filter((item) => Date.parse(item.notBefore) <= now);
const context = { lifts, published, quality, reviews, now };
const choose = (pool, order, how) => {
- for (const tier of order) {
- const ranked = rankItems(pool.filter((item) => tierOf(item) === tier), context);
+ // A kind slot ranks its kind across every tier at once.
+ for (const tier of isKindSlot(slot) ? [null] : order) {
+ const ranked = rankItems(tier == null ? pool : pool.filter((item) => tierOf(item) === tier), context);
if (!ranked.length) continue;
const [top] = ranked;
return {
item: top.item,
slot,
- tier,
- filledDown: tier > slot.tier,
- filledUp: tier < slot.tier,
+ tier: tier ?? tierOf(top.item),
+ filledDown: tier != null && tier > slot.tier,
+ filledUp: tier != null && tier < slot.tier,
vetoYielded: how === 'veto',
score: top.score,
parts: top.parts,
@@ -229,7 +259,7 @@ export function pickDue({
};
const countByTier = (pool) => new Map(TIERS.map((tier) => [tier, pool.filter((item) => tierOf(item) === tier).length]));
- const usual = choose(ready, tierOrder(slot.tier, countByTier(ready)), 'usual');
+ const usual = choose(ready, isKindSlot(slot) ? [] : tierOrder(slot.tier, countByTier(ready)), 'usual');
if (usual || !quota) return usual || empty();
// Three a day is a quota, not a ceiling (owner, 2026-09-30), so a slot is
// never left empty while an approved post could fill it. First a higher
@@ -245,8 +275,9 @@ export function pickDue({
);
function empty() {
- const embargoed = unpublished.filter((item) => !exclude.has(item.id) && Date.parse(item.notBefore) > now).sort((a, b) => a.notBefore.localeCompare(b.notBefore));
+ const embargoed = unpublished.filter((item) => fits(item) && !exclude.has(item.id) && Date.parse(item.notBefore) > now).sort((a, b) => a.notBefore.localeCompare(b.notBefore));
if (embargoed[0]) return { item: null, slot, reason: `nothing is ready for slot ${slot.key}; ${embargoed[0].id} is embargoed until ${embargoed[0].notBefore}` };
- return { item: null, slot, reason: exclude.size ? `every ready post was held this tick; slot ${slot.key} stays open` : 'queue has no approved unpublished posts' };
+ const none = isKindSlot(slot) ? `queue has no approved unpublished ${slot.kind} for slot ${slot.key}` : 'queue has no approved unpublished posts';
+ return { item: null, slot, reason: exclude.size ? `every ready post was held this tick; slot ${slot.key} stays open` : none };
}
}
diff --git a/data/x-content/queue.json b/data/x-content/queue.json
index 84db236ec..1d369e74a 100644
--- a/data/x-content/queue.json
+++ b/data/x-content/queue.json
@@ -18,6 +18,12 @@
{
"tier": 3,
"at": "19:00"
+ },
+ {
+ "kind": "article",
+ "at": "22:30",
+ "everyDays": 2,
+ "from": "2026-10-08"
}
]
},
@@ -69,7 +75,8 @@
2,
3
],
- "vetoHours": 2
+ "vetoHours": 2,
+ "articles": true
},
"items": [
{
diff --git a/tests/x-content-approval.test.js b/tests/x-content-approval.test.js
index 0cd43c3f2..992d9772b 100644
--- a/tests/x-content-approval.test.js
+++ b/tests/x-content-approval.test.js
@@ -62,7 +62,9 @@ describe('approval policy', () => {
it('leaves approval with the owner unless the queue says otherwise', () => {
expect(approvalPolicy({})).toEqual(DEFAULT_APPROVAL);
expect(approvalPolicy({ approval: { mode: 'automatic' } }).mode).toBe('owner');
- expect(approvalPolicy({ approval: { mode: 'auto', tiers: [1, 2, 9, 'x'], vetoHours: 6 } })).toEqual({ mode: 'auto', tiers: [1, 2], vetoHours: 6 });
+ expect(approvalPolicy({ approval: { mode: 'auto', tiers: [1, 2, 9, 'x'], vetoHours: 6 } })).toEqual({ mode: 'auto', tiers: [1, 2], vetoHours: 6, articles: false });
+ expect(approvalPolicy({ approval: { mode: 'auto', articles: 'yes' } }).articles).toBe(false);
+ expect(approvalPolicy({ approval: { mode: 'auto', articles: true } }).articles).toBe(true);
});
it('never shortens the veto window to nothing', () => {
@@ -102,6 +104,23 @@ describe('approval policy', () => {
expect(policyBlockers(item(), null, AUTO, sandbox(), NOW)).toEqual(['its review did not pass']);
});
+ it('releases an Article that passed review when the queue lets articles go by policy', () => {
+ const dir = sandbox();
+ mkdirSync(join(dir, 'data/x-content/articles'), { recursive: true });
+ writeFileSync(join(dir, 'data/x-content/articles/rig.md'), '## How it works\n\nThe retargeter maps every bone.\n');
+ const article = item({ kind: 'article', tier: 1, scenario: undefined, probes: [{ type: 'api', url: 'https://three.ws/api/healthz' }], article: { title: 'How three.ws retargets motion', body: 'data/x-content/articles/rig.md' }, posts: [{ text: 'The long version of how one clip library drives any humanoid skeleton.' }] });
+ const ARTICLES = { ...AUTO, articles: true };
+ expect(policyBlockers(article, PASSED, ARTICLES, dir, NOW)).toEqual([]);
+ // Without the switch an Article is a tier 1 item nobody filmed.
+ expect(policyBlockers(article, PASSED, AUTO, dir, NOW)).toEqual(['tier 1 posts are approved by the owner', 'it was never filmed against the product']);
+ // Every other condition still holds, including a tag deep in the body.
+ expect(policyBlockers(article, { passed: true, editor: { verdict: 'revise' } }, ARTICLES, dir, NOW)).toEqual(["the editor's verdict was revise"]);
+ writeFileSync(join(dir, 'data/x-content/articles/rig.md'), '## Credits\n\nThanks to @nvidia for the GPUs.\n');
+ expect(policyBlockers(article, PASSED, ARTICLES, dir, NOW)).toEqual(['it tags @nvidia']);
+ // A post is not an Article: the switch does not release it unfilmed.
+ expect(policyBlockers(item({ scenario: undefined }), PASSED, ARTICLES, dir, NOW)).toEqual(['it was never filmed against the product']);
+ });
+
it('embargoes a release for the veto window, or longer if the post already waited for more', () => {
expect(vetoUntil(item(), AUTO, NOW)).toBe('2026-09-30T12:00:00.000Z');
expect(vetoUntil(item({ notBefore: '2026-10-05T09:00:00Z' }), AUTO, NOW)).toBe('2026-10-05T09:00:00.000Z');
diff --git a/tests/x-content.test.js b/tests/x-content.test.js
index bc2012d06..cf9a2d3f7 100644
--- a/tests/x-content.test.js
+++ b/tests/x-content.test.js
@@ -6,7 +6,7 @@ import { join } from 'node:path';
import { copyProblems, weightedLength } from '../api/_lib/x-content/quality.js';
import { SPEED_OUTPUT_FPS, attachmentProblems, mediaProblems, parseFfmpegProbe, videoFilterChain } from '../api/_lib/x-content/media.js';
import { markdownToContentState, attachArticleMedia } from '../api/_lib/x-content/articles.js';
-import { DEFAULT_SLOTS, currentSlot, inQuietHours, jitterMinutes, pickDue, slotOpenings, tierOrder } from '../api/_lib/x-content/schedule.js';
+import { DEFAULT_SLOTS, currentSlot, inQuietHours, jitterMinutes, pickDue, slotLabel, slotOpenings, tierOrder } from '../api/_lib/x-content/schedule.js';
import { linkProbeUrl } from '../api/_lib/x-content/verify.js';
import { engagementSignals, loadLifts, loadVolumeModel, rankItems, scoreItem, volumeScore } from '../api/_lib/x-content/priority.js';
import { accountRefusal, activeHolds, inventory, isPostSpecific, placeHold, runTick } from '../api/_lib/x-content/runner.js';
@@ -208,6 +208,34 @@ describe('schedule', () => {
expect(pickDue({ items, state: {}, now: primeTime, cadence, exclude: new Set(['high', 'mid', 'low']) }).reason).toMatch(/held this tick/);
});
+ it('opens an Article slot every second day, keeps Articles for it, and leaves it outside the daily cap', () => {
+ const withArticles = { ...cadence, slots: [...cadence.slots, { kind: 'article', at: '02:00', everyDays: 2, from: '2026-09-17' }] };
+ const articleDays = (from, days) => Array.from({ length: days }, (_, i) => from + i * 24 * HOUR)
+ .filter((day) => slotOpenings(day, withArticles).some((slot) => slot.kind === 'article' && slot.key.startsWith(new Date(day).toISOString().slice(0, 10))))
+ .map((day) => new Date(day).toISOString().slice(0, 10));
+ expect(articleDays(Date.parse('2026-09-15T12:00:00Z'), 6)).toEqual(['2026-09-15', '2026-09-17', '2026-09-19']);
+ expect(slotLabel(slotOpenings(primeTime, withArticles).find((slot) => slot.kind))).toBe('article');
+
+ const article = item('longread', { kind: 'article', tier: 1, priority: 50, article: { title: 'How it works', body: 'x.md' } });
+ const feature = item('feature', { tier: 1 });
+ // The daily slot never spends the Article, however high it ranks.
+ expect(pickDue({ items: [article, feature], state: {}, now: primeTime, cadence: withArticles }).item.id).toBe('feature');
+ expect(pickDue({ items: [article], state: {}, now: primeTime, cadence: withArticles, quota: true }).item).toBeNull();
+ // Without an Article slot an Article is an ordinary tier 1 item.
+ expect(pickDue({ items: [article, feature], state: {}, now: primeTime, cadence }).item.id).toBe('longread');
+
+ // 02:50 on an Article day: the slot takes only Articles, past a full daily cap.
+ const night = Date.parse('2026-09-19T02:50:00Z');
+ const capped = { published: [5, 9, 13].map((h, i) => ({ id: `p${i}`, slot: `s${i}`, publishedAt: new Date(night - h * HOUR).toISOString() })) };
+ const pick = pickDue({ items: [article, feature], state: capped, now: night, cadence: withArticles, quota: true });
+ expect([pick.item.id, pick.slot.kind, pick.tier, pick.filledDown, pick.filledUp]).toEqual(['longread', 'article', 1, false, false]);
+ expect(pickDue({ items: [feature], state: capped, now: night, cadence: withArticles, quota: true }).reason).toMatch(/no approved unpublished article for slot 2026-09-19#3/);
+ // The Article it sent does not count toward the next morning's cap.
+ const sent = { published: [...capped.published.slice(1), { id: 'longread', slot: '2026-09-19#3', slotKind: 'article', publishedAt: new Date(night).toISOString() }] };
+ const morning = Date.parse('2026-09-19T08:50:00Z');
+ expect(pickDue({ items: [item('demo', { tier: 3 })], state: sent, now: morning, cadence: withArticles }).item.id).toBe('demo');
+ });
+
it('resumes a half-published item ahead of pacing and priority', () => {
const state = { published: [{ id: 'p', publishedAt: new Date(primeTime - 10 * 60_000).toISOString() }], inflight: { a: { media: {}, postIds: ['1'] } } };
expect(pickDue({ items: [item('a'), item('b', { priority: 50 })], state, now: primeTime, cadence }).resuming).toBe(true);
@@ -258,22 +286,28 @@ describe('priority', () => {
expect(scored.volumeChance).toBeNull();
});
- it('spaces the three daily slots eight hours apart, far enough that all three can post', () => {
- // Owner cadence (2026-09-20): three posts a day, eight hours apart, every
- // day. That replaced the volume-study window (12:00 to 20:00 UTC), which
- // could not hold three slots without crowding them.
+ it('keeps the three daily slots inside the volume window, and every slot far enough apart that all of them can post', () => {
+ // Owner cadence (2026-10-01): three posts a day inside 12:00 to 20:00 UTC,
+ // where the volume study found a post is most often followed by a volume
+ // response. Owner directive (2026-10-08): one X Article every second day,
+ // in its own slot after the last daily post.
const queue = loadQueue(root);
- const slots = queue.cadence.slots;
- expect(slots).toHaveLength(3);
- const minutes = slots.map((slot) => Number(slot.at.slice(0, 2)) * 60 + Number(slot.at.slice(3))).sort((a, b) => a - b);
- for (let index = 1; index < minutes.length; index++) expect(minutes[index] - minutes[index - 1]).toBe(8 * 60);
- // Wrapping past midnight, the last slot to the first is also eight hours.
- expect(minutes[0] + 24 * 60 - minutes[minutes.length - 1]).toBe(8 * 60);
+ const toMinutes = (at) => Number(at.slice(0, 2)) * 60 + Number(at.slice(3));
+ const daily = queue.cadence.slots.filter((slot) => !slot.kind);
+ expect(daily).toHaveLength(3);
+ for (const slot of daily) {
+ expect(toMinutes(slot.at)).toBeGreaterThanOrEqual(12 * 60);
+ expect(toMinutes(slot.at) + queue.cadence.windowMinutes).toBeLessThanOrEqual(20 * 60);
+ }
+ expect(queue.cadence.slots.filter((slot) => slot.kind)).toEqual([{ kind: 'article', at: '22:30', everyDays: 2, from: '2026-10-08' }]);
// The latest a slot can open, to the earliest the next one can: never closer
// than the minimum gap, or the later slot would be blocked by the earlier post.
- for (let index = 1; index < minutes.length; index++) {
- expect(minutes[index] - (minutes[index - 1] + queue.cadence.windowMinutes)).toBeGreaterThanOrEqual(queue.cadence.minimumMinutesApart);
+ // The Article evening is the tightest day, so measure every slot together.
+ const minutes = queue.cadence.slots.map((slot) => toMinutes(slot.at)).sort((a, b) => a - b);
+ for (let index = 1; index <= minutes.length; index++) {
+ const next = index < minutes.length ? minutes[index] : minutes[0] + 24 * 60;
+ expect(next - (minutes[index - 1] + queue.cadence.windowMinutes)).toBeGreaterThanOrEqual(queue.cadence.minimumMinutesApart);
}
});
@@ -285,8 +319,8 @@ describe('priority', () => {
const saturday = Date.parse('2026-09-19T16:20:00Z');
const sunday = Date.parse('2026-09-20T16:20:00Z');
const monday = Date.parse('2026-09-21T16:45:00Z');
- const tiersOn = (day) => slotOpenings(day, cadence, 'seed').filter((slot) => slot.key.startsWith(new Date(day).toISOString().slice(0, 10))).map((slot) => slot.tier);
- const everyDay = cadence.slots.map((slot) => Number(slot.tier));
+ const tiersOn = (day) => slotOpenings(day, cadence, 'seed').filter((slot) => !slot.kind && slot.key.startsWith(new Date(day).toISOString().slice(0, 10))).map((slot) => slot.tier);
+ const everyDay = cadence.slots.filter((slot) => !slot.kind).map((slot) => Number(slot.tier));
for (const day of [saturday, sunday, monday]) expect(tiersOn(day)).toEqual(everyDay);
// A weekend flagship slot goes to a flagship post, not down to a feature.
@@ -383,6 +417,16 @@ describe('holds and fall-through', () => {
];
const stock = inventory(items, { published: [{ id: 'a' }] }, dir);
expect(stock).toEqual([{ tier: 1, days: 0, low: true }, { tier: 2, days: 3, low: false }, { tier: 3, days: 0, low: true }]);
+
+ // An Article slot every two days: Articles are counted for it, not for their tier.
+ items.push({ id: 'f', status: 'approved', tier: 1, kind: 'article', article: { title: 'f' } });
+ const cadence = { slots: [{ tier: 1, at: '15:30' }, { kind: 'article', at: '22:30', everyDays: 2 }] };
+ expect(inventory(items, { published: [{ id: 'a' }] }, dir, Date.now(), cadence)).toEqual([
+ { tier: 1, days: 0, low: true },
+ { tier: 2, days: 3, low: false },
+ { tier: 3, days: 0, low: true },
+ { kind: 'article', count: 1, days: 2, low: true },
+ ]);
});
it('never ends a tick on a failed post: it holds it and publishes the next best', async () => {