Lower threshold - Only the code is required: the title is optional and named after the bullet or file. Paste a fix right on a bullet (web), drop or load several files, and optionally say where it goes and what it replaces. - A "patch" that is not a diff is kept as a snippet; the same code sent twice returns the existing change. MCP - submit_change works with just `code` (+ fixes, path, replaces, note). - get_change_bundle returns review warnings, the steps to land the batch and short-lived download links for the mbox and code sheet. - review_changes records the version a batch landed in. - Prompts: fix_bullet and land_code_changes. Review safety - Encoded or multipart format-patch messages are refused and only From/Date/Subject headers reach git am. - Warnings for invisible/text-direction characters (shown spelled out), build/CI/script files, binaries, symlinks and executable bits. - The code sheet and MCP results mark contributor content as untrusted; descriptions are quoted. - Commit author e-mails are only shown to admins and the submitter. - Code counts against the upload budget; 30 waiting changes per tester. Fixes - Revising no longer drops a snippet's note; archived-project fallback; no literal invisible characters in the source. - Android: one-line Bullets header, discard confirmation in the submit form, wrapping stats row.
217 lines
14 KiB
JavaScript
217 lines
14 KiB
JavaScript
#!/usr/bin/env node
|
|
/* Fills a FRESH PIKKIE instance with demo data (fictional testers, projects, bullets, a poll…).
|
|
* PIKKIE_DATA=/tmp/pikkie-demo PORT=1313 node server/src/index.js &
|
|
* node scripts/seed-demo.mjs http://localhost:1313
|
|
* Prints the demo admin login at the end. Never run this against a real instance.
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import crypto from 'node:crypto';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const BASE = (process.argv[2] || 'http://localhost:1313').replace(/\/$/, '');
|
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
const PW = crypto.randomBytes(9).toString('base64url');
|
|
|
|
const jars = {};
|
|
async function call(who, method, url, body) {
|
|
const headers = {};
|
|
if (jars[who]) headers.cookie = jars[who];
|
|
let payload = body;
|
|
if (body && !(body instanceof FormData)) {
|
|
headers['content-type'] = 'application/json';
|
|
payload = JSON.stringify(body);
|
|
}
|
|
const r = await fetch(BASE + url, { method, headers, body: payload });
|
|
const sc = r.headers.get('set-cookie');
|
|
if (sc) jars[who] = sc.split(';')[0];
|
|
const j = await r.json().catch(() => ({}));
|
|
if (!r.ok) throw new Error(`${method} ${url}: ${j.error || r.status}`);
|
|
return j;
|
|
}
|
|
const status = await call('anon', 'GET', '/api/status');
|
|
if (!status.needs_setup) {
|
|
console.error('This instance is already set up. The demo seeder only runs on a fresh, empty instance.');
|
|
process.exit(1);
|
|
}
|
|
|
|
const people = {
|
|
admin: { email: 'captain@demo.test', name: 'Captain Picky' },
|
|
mosh: { email: 'mosh@demo.test', name: 'Mosh' },
|
|
riot: { email: 'riot@demo.test', name: 'Riot Grrl' },
|
|
nul: { email: 'null@demo.test', name: 'NullPointer' },
|
|
sk8: { email: 'sk8@demo.test', name: 'Sk8 Vicious' },
|
|
};
|
|
await call('admin', 'POST', '/api/setup', { ...people.admin, password: PW });
|
|
for (const k of ['mosh', 'riot', 'nul', 'sk8']) {
|
|
await call('admin', 'POST', '/api/admin/users', { ...people[k], password: PW, role: 'tester' });
|
|
await call(k, 'POST', '/api/login', { email: people[k].email, password: PW });
|
|
}
|
|
|
|
const proj = {};
|
|
await call('admin', 'PATCH', '/api/admin/projects/1', { name: 'Website', description: 'The marketing site + web app', color: '#6cb6ff' });
|
|
proj.web = 1;
|
|
proj.app = (await call('admin', 'POST', '/api/admin/projects', { name: 'Android app', description: 'The phone app, all flavours', color: '#3ddc97' })).id;
|
|
proj.api = (await call('admin', 'POST', '/api/admin/projects', { name: 'Sync engine', description: 'Offline sync & backend', color: '#ff2e93' })).id;
|
|
|
|
const logoPng = fs.existsSync(path.join(here, '..', 'docs', 'assets', 'attachment.png'))
|
|
? fs.readFileSync(path.join(here, '..', 'docs', 'assets', 'attachment.png'))
|
|
: null;
|
|
async function report(who, project, bullets, { weight, version, files = [] } = {}) {
|
|
const fd = new FormData();
|
|
fd.append('bullets', bullets);
|
|
fd.append('project_id', String(project));
|
|
if (weight) fd.append('weight', String(weight));
|
|
if (version) fd.append('version', version);
|
|
for (const [name, buf, type] of files) fd.append('files', new Blob([buf], { type }), name);
|
|
return (await call(who, 'POST', '/api/reports', fd)).ids;
|
|
}
|
|
async function flag(id, status, message) {
|
|
const fd = new FormData();
|
|
fd.append('status', status);
|
|
fd.append('message', message);
|
|
return call('admin', 'POST', `/api/items/${id}/status`, fd);
|
|
}
|
|
async function comment(who, id, body, parent) {
|
|
const fd = new FormData();
|
|
fd.append('body', body);
|
|
if (parent) fd.append('parent_id', String(parent));
|
|
return (await call(who, 'POST', `/api/items/${id}/comments`, fd)).id;
|
|
}
|
|
|
|
const a = await report('mosh', proj.app, '- [12g] App crashes when you rotate on the login screen\n- [.45] Toast covers the save button\n- Back button closes the app instead of going back', {
|
|
weight: 2, version: '0.9.3', files: logoPng ? [['crash-screenshot.png', logoPng, 'image/png']] : [],
|
|
});
|
|
const b = await report('riot', proj.web, '- [.22] Logo kerning is 1px off on Safari\n- [9mm] Dark mode chart legend is unreadable\n legend text is #333 on #222\n- [7.62] Password reset mail never arrives', { version: '2.1.0' });
|
|
const c = await report('nul', proj.api, '- [12 gauge] Offline edits vanish after sync conflict\n- [7.62] Sync spinner spins forever on flaky wifi', { version: '0.9.3' });
|
|
const d = await report('sk8', proj.app, '- [.22] Settings icon is slightly blurry on Pixel\n- [9mm] Haptic feedback fires twice on long-press', { version: '0.9.3' });
|
|
|
|
await flag(a[0], 'fixed', 'Rotation handled properly now. Ships in 0.9.4. Thanks for the stack trace!');
|
|
await flag(b[2], 'needs_info', 'Which mail provider? Can you check your spam folder?');
|
|
await flag(c[0], 'in_progress', 'Reproduced. Working on a merge strategy.');
|
|
await flag(b[0], 'declined', 'Safari renders it that way on purpose, we will leave it.');
|
|
await flag(d[1], 'finished', 'Single haptic now, verified on 3 devices.');
|
|
|
|
const t1 = await comment('sk8', c[0], 'Same here, lost a whole shopping list 😭');
|
|
await comment('nul', c[0], 'Happens when two devices edit the same note within ~5 seconds.', t1);
|
|
await comment('mosh', c[0], 'Can confirm on a tablet too.');
|
|
for (const who of ['mosh', 'riot', 'sk8']) await call(who, 'POST', `/api/items/${c[0]}/metoo`);
|
|
await call('riot', 'POST', `/api/items/${a[1]}/metoo`);
|
|
await comment('riot', b[2], 'Gmail. Nothing in spam either.');
|
|
|
|
const key = (await call('admin', 'POST', '/api/keys', { name: 'fixbot' })).key;
|
|
await fetch(`${BASE}/mcp`, {
|
|
method: 'POST',
|
|
headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
|
|
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'submit_bullets', arguments: { project: 'Sync engine', bullets: ['[7.62] Retry loop ignores HTTP 429 Retry-After header'] } } }),
|
|
});
|
|
await fetch(`${BASE}/mcp`, {
|
|
method: 'POST',
|
|
headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
|
|
body: JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'set_status', arguments: { id: c[1], status: 'fixed', message: 'Added exponential backoff with jitter and a 30s cap. PR #42.' } } }),
|
|
});
|
|
|
|
// --- code changes: a small review queue (two of them touch the same file)
|
|
const keyOf = async (who, name) => (await call(who, 'POST', '/api/keys', { name })).key;
|
|
const tool = async (k, name, args) => {
|
|
const r = await fetch(`${BASE}/mcp`, { method: 'POST', headers: { authorization: `Bearer ${k}`, 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 3, method: 'tools/call', params: { name, arguments: args } }) }).then((x) => x.json());
|
|
return JSON.parse(r.result.content[0].text);
|
|
};
|
|
const diff = (file, at, before, after, ctx = []) => [
|
|
`diff --git a/${file} b/${file}`, `index 3f1c2aa..8b0e7d1 100644`, `--- a/${file}`, `+++ b/${file}`,
|
|
`@@ -${at},${before.length + ctx.length} +${at},${after.length + ctx.length} @@`, ...ctx.map((l) => ' ' + l), ...before.map((l) => '-' + l), ...after.map((l) => '+' + l), '',
|
|
].join('\n');
|
|
const nulKey = await keyOf('nul', 'claude-code');
|
|
const merge = await tool(nulKey, 'submit_change', {
|
|
title: 'Merge concurrent note edits instead of last-write-wins',
|
|
description: 'Two devices editing within the sync window now get a three-way merge on paragraphs.\nConflicting paragraphs are kept side by side with a marker instead of silently dropped.',
|
|
fixes: [c[0]], base: 'main @ 4e1d9b2',
|
|
patch: diff('sync/merge.js', 12, [' return remote.updated > local.updated ? remote : local;'], [' if (!base) return remote.updated > local.updated ? remote : local;', ' return mergeParagraphs(base, local, remote);'], ['export function resolve(base, local, remote) {'])
|
|
+ diff('sync/paragraphs.js', 1, [], ['export function mergeParagraphs(base, a, b) {', ' // keep both sides of a real conflict, marked', ' return threeWay(split(base), split(a), split(b)).join("\\n\\n");', '}']),
|
|
});
|
|
await tool(await keyOf('sk8', 'sk8-agent'), 'submit_change', {
|
|
title: 'Honour Retry-After on HTTP 429', project: 'Sync engine',
|
|
description: 'The retry loop now waits as long as the server asks (capped at 5 minutes) before backing off further.',
|
|
patch: diff('sync/retry.js', 30, [' await sleep(backoff(attempt));'], [' const wait = retryAfter(res) ?? backoff(attempt);', ' await sleep(Math.min(wait, 300_000));'], [' if (res.status === 429) {'])
|
|
+ diff('sync/merge.js', 40, [' log("merge", id);'], [' log("merge", id, { attempt });'], []),
|
|
});
|
|
const riotChange = (await call('riot', 'POST', '/api/changes', (() => {
|
|
const fd = new FormData();
|
|
fd.append('title', 'Header logo sits 1px too low');
|
|
fd.append('description', 'Align the logo baseline with the nav links.');
|
|
fd.append('fixes', String(b[0]));
|
|
fd.append('patch_file', new Blob([diff('web/header.css', 8, [' margin-top: 3px;'], [' margin-top: 2px;'], ['.brand img {'])]), 'logo.patch');
|
|
return fd;
|
|
})())).id;
|
|
await call('admin', 'POST', '/api/admin/changes/review', { ids: [riotChange], status: 'accepted', message: 'Pixel-perfect. Landed in 0.9.4 🤘', fix_issues: true });
|
|
const mosh = await tool(await keyOf('mosh', 'mosh-bot'), 'submit_change', {
|
|
title: 'Keep scroll position on rotate',
|
|
patch: diff('android/ListScreen.kt', 22, [' val state = rememberLazyListState()'], [' val state = rememberSaveable(saver = LazyListState.Saver) { LazyListState() }'], ['@Composable fun ListScreen() {']),
|
|
});
|
|
await call('admin', 'POST', '/api/admin/changes/review', { ids: [mosh.id], status: 'needs_work', message: 'Nice! Can you add the same to the board list?' });
|
|
// a tester without access to the repository: just the code, and where it goes
|
|
await call('riot', 'POST', '/api/changes', (() => {
|
|
const fd = new FormData();
|
|
fd.append('title', 'Readable chart legend in dark mode');
|
|
fd.append('description', "I don't have the repo, but this fixes it in my browser's dev tools.");
|
|
fd.append('fixes', String(b[1]));
|
|
fd.append('snippets_file', new Blob([JSON.stringify([
|
|
{ path: 'web/charts.css', note: 'the legend rule near the bottom', replaces: '.legend text {\n fill: #333;\n}', content: '.legend text {\n fill: var(--text);\n font-weight: 600;\n}' },
|
|
{ content: '// wherever the chart theme is built:\nlegend: { labels: { color: getComputedStyle(document.body).getPropertyValue("--text") } }' },
|
|
])], { type: 'application/json' }), 'snippets.json');
|
|
return fd;
|
|
})());
|
|
await call('nul', 'POST', `/api/changes/${merge.id}/notes`, { body: 'Tested on two phones and a tablet editing the same note: no more lost lines.' });
|
|
|
|
const poll = (await call('riot', 'POST', '/api/posts', { type: 'poll', title: 'Codename for the next release?', body: 'Vote, picky ones 🤘', options: ['Safety Pin', 'Mohawk', 'Tiny Riot'] })).id;
|
|
const opts = (await call('riot', 'GET', `/api/posts/${poll}`)).options;
|
|
await call('mosh', 'POST', `/api/posts/${poll}/vote`, { option_id: opts[2].id });
|
|
await call('sk8', 'POST', `/api/posts/${poll}/vote`, { option_id: opts[2].id });
|
|
await call('nul', 'POST', `/api/posts/${poll}/vote`, { option_id: opts[1].id });
|
|
await call('admin', 'POST', `/api/posts/${poll}/pin`, { pinned: true });
|
|
const post = (await call('mosh', 'POST', '/api/posts', { title: 'Beta 0.9.3 feels fast!', body: 'Startup went from 3s to under 1s on my old phone. Nice work.' })).id;
|
|
await call('nul', 'POST', `/api/posts/${post}/replies`, { body: 'Agreed, scrolling is buttery now.' });
|
|
|
|
await call('admin', 'POST', '/api/admin/invites', { emails: 'newbie@demo.test, punk@demo.test', message: 'Welcome to the beta!' });
|
|
|
|
// --- social: avatars, bios, off-topic board
|
|
const art = (f) => {
|
|
const fp = path.join(here, '..', 'docs', 'assets', 'demo', f);
|
|
return fs.existsSync(fp) ? fs.readFileSync(fp) : null;
|
|
};
|
|
const bios = {
|
|
admin: ['captain', 'Herding bugs since 2009. Will flag your bullet as needs-info at 3am.'],
|
|
mosh: ['mosh', 'Android power user. Rotates screens for fun. 12 gauge enthusiast.'],
|
|
riot: ['riot', 'Front-end nitpicker. If it is 1px off, I will find it.'],
|
|
nul: ['null', 'Breaks sync engines for a living. Ask me about race conditions.'],
|
|
sk8: ['sk8', 'Tests on 6 phones, one of them held together with tape.'],
|
|
};
|
|
for (const [who, [file, bio]] of Object.entries(bios)) {
|
|
const png = art(`av-${file}.png`);
|
|
if (png) {
|
|
const fd = new FormData();
|
|
fd.append('avatar', new Blob([png], { type: 'image/png' }), 'avatar.png');
|
|
await call(who, 'POST', '/api/me/avatar', fd);
|
|
}
|
|
await call(who, 'PATCH', '/api/me', { bio, tutorial_done: true }); // demo users skip the first-run tour
|
|
}
|
|
async function boardPost(who, board, title, body, images = []) {
|
|
const fd = new FormData();
|
|
fd.append('board', board);
|
|
fd.append('title', title);
|
|
fd.append('body', body);
|
|
for (const f of images) { const b = art(f); if (b) fd.append('files', new Blob([b], { type: 'image/png' }), f); }
|
|
return (await call(who, 'POST', '/api/posts', fd)).id;
|
|
}
|
|
const m1 = await boardPost('mosh', 'offtopic', 'every single standup', 'you know the one', ['meme-works.png']);
|
|
await boardPost('riot', 'offtopic', 'my QA lead, apparently', '', ['meme-cat.png']);
|
|
await boardPost('nul', 'offtopic', 'new desk setup 🎛️', 'finally cable-managed. ignore the 14 test phones.', ['meme-setup.png', 'meme-works.png']);
|
|
if (process.env.DEMO_OFFLINE !== '1') await boardPost('sk8', 'offtopic', 'testing soundtrack', 'this is what I blast while hunting 12 gauges https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
|
const rfd = new FormData();
|
|
rfd.append('body', 'literally me yesterday 😂');
|
|
const cat = art('meme-cat.png');
|
|
if (cat) rfd.append('files', new Blob([cat], { type: 'image/png' }), 'reply.png');
|
|
await call('riot', 'POST', `/api/posts/${m1}/replies`, rfd);
|
|
|
|
console.log(`Demo ready on ${BASE}\n admin: ${people.admin.email}\n testers: ${['mosh', 'riot', 'nul', 'sk8'].map((k) => people[k].email).join(', ')}\n password (all): ${PW}`);
|