okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-020-reset' into f-020-intf57c0adcb

main
9.4 KiB192 linesraw
1'use strict';
2const test = require('node:test');
3const assert = require('node:assert');
4const c = require('./item-check');
5const bot = require('./reset-bot');
6
7const bugForm = (over = {}) => {
8  const f = {
9    'Area': '[Engine]  (speed, kernels, models, the server and API)',
10    'Desktop app, Terminal or source?': 'Terminal (the `strata` command)',
11    'What happened': 'Decode stops after two minutes with "CUDA error 700". I expected it to continue.',
12    'Smallest steps or command that reproduce it': '_No response_',
13    'Reproduction status': 'Reproduced locally',
14    'Strata version': 'Strata 0.2.0-beta · engine 0.1.45.3',
15    'Graphics card, memory and system': 'RTX 5070 12 GB · 64 GB RAM · Windows 11',
16    ...over,
17  };
18  return Object.entries(f).map(([k, v]) => `### ${k}\n\n${v}`).join('\n\n');
19};
20
21test('title prefix', () => {
22  assert.ok(c.hasAreaPrefix('[Engine] fix decode'));
23  assert.ok(c.hasAreaPrefix('[Docs] x'));
24  assert.ok(!c.hasAreaPrefix('Engine fix'));
25  assert.ok(!c.hasAreaPrefix('[engine] fix'));
26  assert.ok(!c.hasAreaPrefix('[Engine]'));
27  assert.ok(!c.hasAreaPrefix('[Engine] '));
28  assert.ok(!c.hasAreaPrefix('[Area] foo'));
29  assert.ok(!c.hasAreaPrefix(''));
30  assert.ok(!c.hasAreaPrefix(undefined));
31});
32
33test('filled bug form passes in both modes', () => {
34  for (const mode of ['intake', 'reopen']) {
35    const r = c.checkIssue({ title: '[Engine] decode stops', body: bugForm(), labels: ['bug'], mode });
36    assert.deepStrictEqual(r.missing, []);
37    assert.strictEqual(r.kind, 'bug');
38  }
39});
40
41test('bug form: missing parts are named', () => {
42  const r = c.checkIssue({ title: 'decode stops', body: bugForm({ 'Strata version': '_No response_', 'What happened': 'bad' }) });
43  assert.ok(!r.ok);
44  assert.ok(r.missing.some((m) => /title/i.test(m)));
45  assert.ok(r.missing.some((m) => m.includes('What happened')));
46  assert.ok(r.missing.some((m) => m.includes('Strata version')));
47});
48
49test('reopen needs a 0.2 version, intake does not', () => {
50  const body = bugForm({ 'Strata version': 'Strata 0.1.44' });
51  assert.ok(c.checkIssue({ title: '[Engine] x y', body, mode: 'intake' }).ok);
52  const r = c.checkIssue({ title: '[Engine] x y', body, mode: 'reopen' });
53  assert.ok(!r.ok);
54  assert.ok(r.missing.some((m) => m.includes('0.2.0-beta')));
55});
56
57test('html comments and placeholders do not count', () => {
58  const r = c.checkIssue({ title: '[Engine] x y', body: bugForm({ 'What happened': '<!-- describe -->' }) });
59  assert.ok(r.missing.some((m) => m.includes('What happened')));
60});
61
62test('feature and question forms', () => {
63  const f = '### Area\n\n[GUI]  (the desktop app)\n\n### What do you want to do?\n\nLet me pin a model to the top of the list in the app.';
64  assert.ok(c.checkIssue({ title: '[GUI] pin models', body: f, mode: 'reopen' }).ok);
65  assert.ok(!c.checkIssue({ title: '[GUI] pin models', body: '### Area\n\n[GUI]\n\n### What do you want to do?\n\n_No response_' }).ok);
66  const q = '### Area\n\n[Other]\n\n### Your question\n\nHow do I move the model folder to another drive?';
67  assert.ok(c.checkIssue({ title: '[Other] model folder', body: q }).ok);
68});
69
70test('free-form issue', () => {
71  const good = 'Strata 0.2.0-beta on an RTX 3060 12 GB with 32 GB RAM on Linux: the server hangs when I send two requests at once. Expected both to finish.';
72  assert.ok(c.checkIssue({ title: '[Engine] hang on two requests', body: good, mode: 'reopen' }).ok);
73  assert.ok(!c.checkIssue({ title: '[Engine] hang', body: 'it crashes', mode: 'intake' }).ok);
74  const old = good.replace('0.2.0-beta', '0.1.40');
75  assert.ok(c.checkIssue({ title: '[Engine] hang', body: old, mode: 'intake' }).ok);
76  assert.ok(!c.checkIssue({ title: '[Engine] hang', body: old, mode: 'reopen' }).ok);
77  assert.ok(c.checkIssue({ title: '[Other] idea', body: 'It would help if the app remembered my last model between runs, today I pick it again.', labels: ['enhancement'], mode: 'reopen' }).ok);
78});
79
80const prBody = (over = {}) => {
81  const p = {
82    problem: 'Decode stopped on prompts above 8k because the stop check read the wrong length. Now it continues.',
83    validation: '**Passed:** `ctest -R decode`, commit abcdef1, RTX 3060, 12 of 12.\n\n**Failed:** none observed\n\n**Not run:** HIP build',
84    ...over,
85  };
86  return `## Problem and result\n<!-- hint -->\n${p.problem}\n\n## Related discussion\nnone\n\n## Approach\nFix the length.\n\n## Validation\n${p.validation}\n\n## Limits\nnone`;
87};
88
89test('filled PR passes', () => {
90  assert.deepStrictEqual(c.checkPull({ title: '[Engine] fix stop', body: prBody(), mode: 'reopen' }).missing, []);
91});
92
93test('untouched PR template fails', () => {
94  const tpl = '## Problem and result\n<!-- What triggered -->\n\n## Validation\n<!-- cmds -->\n\n**Passed:**\n<!-- x -->\n\n**Failed:**\n\n**Not run:**\n';
95  const r = c.checkPull({ title: '[Engine] fix stop', body: tpl });
96  assert.ok(!r.ok);
97  assert.ok(r.missing.some((m) => m.includes('Problem and result')));
98  assert.ok(r.missing.some((m) => m.includes('Validation')));
99});
100
101test('PR: empty body and bad title', () => {
102  const r = c.checkPull({ title: 'fix', body: null });
103  assert.ok(!r.ok);
104  assert.ok(r.missing.length >= 2);
105});
106
107test('PR reopen needs a revision', () => {
108  const body = prBody({ validation: '**Passed:** I tried it and it worked for me on my machine, looked fine.' });
109  assert.ok(c.checkPull({ title: '[Engine] x y', body, mode: 'intake' }).ok);
110  assert.ok(!c.checkPull({ title: '[Engine] x y', body, mode: 'reopen' }).ok);
111});
112
113test('free-form PR', () => {
114  const body = 'This fixes a crash when the context is above 8k, because the length was read from the wrong field. Before it aborted, after it continues. I built it on CUDA and ran the decode test, passed.';
115  assert.ok(c.checkPull({ title: '[Engine] fix crash', body }).ok);
116  assert.ok(!c.checkPull({ title: '[Engine] fix crash', body: 'fixes stuff' }).ok);
117});
118
119test('messages', () => {
120  const m = c.intakeComment(false, ['a', 'b']);
121  assert.ok(m.includes('- [ ] a') && m.includes('/reopen') && m.includes('CONTRIBUTING.md'));
122  assert.ok(c.staleComment(true).includes('/reopen'));
123});
124
125// handlers with a fake GitHub client
126function fake(calls, extra = {}) {
127  const rest = {
128    issues: {
129      getLabel: async () => ({}),
130      createLabel: async (a) => calls.push(['createLabel', a.name]),
131      addLabels: async (a) => calls.push(['addLabels', a.labels]),
132      removeLabel: async (a) => calls.push(['removeLabel', a.name]),
133      createComment: async (a) => calls.push(['comment', a.body]),
134      update: async (a) => calls.push(['update', a.state]),
135      get: async () => ({ data: extra.live }),
136      listEvents: async () => {},
137      listForRepo: async () => {},
138    },
139    pulls: { get: async () => ({ data: { mergeable_state: 'clean' } }) },
140  };
141  return { rest, paginate: async (fn) => (fn === rest.issues.listEvents ? (extra.events || []) : (extra.items || [])) };
142}
143const core = { info() {} };
144const repo = { owner: 'o', repo: 'r' };
145
146test('intake labels and comments once', async () => {
147  const calls = [];
148  const item = { number: 1, title: 'bad', body: '', labels: [], user: { type: 'User' }, author_association: 'NONE' };
149  await bot.intake({ github: fake(calls), context: { repo, payload: { action: 'opened', issue: item } }, core });
150  assert.deepStrictEqual(calls.map((c) => c[0]), ['addLabels', 'comment']);
151  calls.length = 0;
152  item.labels = [{ name: 'needs-format' }];
153  await bot.intake({ github: fake(calls), context: { repo, payload: { action: 'edited', issue: item } }, core });
154  assert.deepStrictEqual(calls, []);
155});
156
157test('intake clears the label when edited into shape', async () => {
158  const calls = [];
159  const item = { number: 1, title: '[Engine] x y', body: bugForm(), labels: [{ name: 'needs-format' }], user: { type: 'User' } };
160  await bot.intake({ github: fake(calls), context: { repo, payload: { action: 'edited', issue: item } }, core });
161  assert.deepStrictEqual(calls.map((c) => c[0]), ['removeLabel', 'comment']);
162});
163
164test('reopen: ignores strangers, reopens the author when it passes', async () => {
165  const issue = { number: 5, state: 'closed', user: { login: 'amy' }, labels: [] };
166  let calls = [];
167  const comment = { body: '/reopen', user: { login: 'bob', type: 'User' }, author_association: 'NONE' };
168  await bot.reopen({ github: fake(calls), context: { repo, payload: { issue, comment } }, core });
169  assert.deepStrictEqual(calls, []);
170
171  const live = { number: 5, title: '[Engine] x y', body: bugForm(), labels: [] };
172  comment.user.login = 'amy';
173  await bot.reopen({ github: fake(calls, { live }), context: { repo, payload: { issue, comment } }, core });
174  assert.deepStrictEqual(calls.map((c) => c[0]), ['update', 'removeLabel', 'comment']);
175  assert.strictEqual(calls[0][1], 'open');
176
177  calls = [];
178  live.title = 'no prefix';
179  await bot.reopen({ github: fake(calls, { live }), context: { repo, payload: { issue, comment } }, core });
180  assert.deepStrictEqual(calls.map((c) => c[0]), ['comment']);
181  assert.ok(calls[0][1].includes('Not reopened'));
182});
183
184test('sweep closes only old flagged items', async () => {
185  const calls = [];
186  const old = new Date(Date.now() - 6 * 86400000).toISOString();
187  const fresh = new Date(Date.now() - 1 * 86400000).toISOString();
188  const mk = (n, created) => ({ number: n, title: 'bad', body: '', labels: [{ name: 'needs-format' }], created_at: created });
189  const gh = fake(calls, { items: [mk(1, old), mk(2, fresh)] });
190  await bot.sweep({ github: gh, context: { repo }, core });
191  assert.deepStrictEqual(calls.map((c) => c[0]), ['comment', 'update']);
192});