pi-odd-worktree 3.11.0 → 3.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extensions/odd-worktree-tools.ts +111 -40
- package/lib/gh-prs.js +4 -1
- package/lib/issue-preview.js +53 -10
- package/lib/issues-view.js +55 -21
- package/lib/pr-preview.js +36 -5
- package/lib/prs-view.js +398 -65
- package/lib/user-prompt-card.js +68 -10
- package/package.json +1 -1
- package/tools/gh-prs.test.js +5 -1
- package/tools/issue-preview.test.js +113 -0
- package/tools/issues-command.test.js +8 -5
- package/tools/issues-view.test.js +130 -0
- package/tools/pr-preview.test.js +134 -0
- package/tools/prs-command.test.js +49 -0
- package/tools/prs-view.test.js +350 -5
- package/tools/user-prompt-card.test.js +173 -6
package/tools/prs-view.test.js
CHANGED
|
@@ -116,6 +116,7 @@ function makeView(opts = {}) {
|
|
|
116
116
|
|| ((number) => ({ ok: true, pullRequest: pullRequest(number), comments: [] })),
|
|
117
117
|
loadLabels: opts.loadLabels,
|
|
118
118
|
loadAssignees: opts.loadAssignees,
|
|
119
|
+
loadIssueCandidates: opts.loadIssueCandidates,
|
|
119
120
|
permissions: opts.permissions,
|
|
120
121
|
labels: opts.labels,
|
|
121
122
|
actions,
|
|
@@ -162,6 +163,23 @@ function deferred() {
|
|
|
162
163
|
return { promise, resolve };
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
// T20: the linked-issues candidate seam. `pages` is one entry per read, each
|
|
167
|
+
// with the rows it answers, the cursor that continues AFTER it, and whether the
|
|
168
|
+
// repository has more; every request is recorded. A read request with `after`
|
|
169
|
+
// continues from the page whose cursor it names.
|
|
170
|
+
function candidateSource(pages, options = {}) {
|
|
171
|
+
const calls = [];
|
|
172
|
+
const load = async (request) => {
|
|
173
|
+
calls.push(request);
|
|
174
|
+
if (typeof options.fail === 'string') return { ok: false, error: options.fail };
|
|
175
|
+
const after = request.after == null ? null : request.after;
|
|
176
|
+
const at = after === null ? 0 : pages.findIndex((page) => page.cursor === after) + 1;
|
|
177
|
+
const page = pages[at] || { rows: [], hasMore: false, cursor: null };
|
|
178
|
+
return { ok: true, rows: page.rows, hasMore: page.hasMore === true, cursor: page.cursor ?? null };
|
|
179
|
+
};
|
|
180
|
+
return { load, calls };
|
|
181
|
+
}
|
|
182
|
+
|
|
165
183
|
// S3: the reader asks view-layout for the smaller 30% list share, so every
|
|
166
184
|
// geometry helper here reads the same allocation the view paints.
|
|
167
185
|
function readerPanes(width) {
|
|
@@ -1016,31 +1034,235 @@ describe('prs view writes (S2)', () => {
|
|
|
1016
1034
|
test('i edits the linked issues as add/remove deltas', async () => {
|
|
1017
1035
|
const applied = [];
|
|
1018
1036
|
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1037
|
+
// T20: `n` opens the candidate list, so the added number is PICKED there and
|
|
1038
|
+
// never typed into a bare field.
|
|
1039
|
+
const candidates = candidateSource([{
|
|
1040
|
+
rows: [
|
|
1041
|
+
{ number: 12, title: 'Twelve', state: 'open' },
|
|
1042
|
+
{ number: 14, title: 'Fourteen', state: 'open' },
|
|
1043
|
+
{ number: 77, title: 'Seventy seven', state: 'open' },
|
|
1044
|
+
],
|
|
1045
|
+
hasMore: false,
|
|
1046
|
+
cursor: null,
|
|
1047
|
+
}]);
|
|
1019
1048
|
const { view } = makeView({
|
|
1020
1049
|
loadPullRequestPage: source.load,
|
|
1021
1050
|
loadPullRequest: (number) => ({ ok: true, pullRequest: pullRequest(number, { permissions: EDITABLE }), comments: [] }),
|
|
1051
|
+
loadIssueCandidates: candidates.load,
|
|
1022
1052
|
actions: { editLinkedIssues: (number, delta) => { applied.push({ number, delta }); return { ok: true }; } },
|
|
1023
1053
|
});
|
|
1024
1054
|
await tick();
|
|
1025
1055
|
view.handleInput('i');
|
|
1056
|
+
await tick();
|
|
1026
1057
|
assert.equal(view.state.mode, 'linkedIssues');
|
|
1027
1058
|
let pane = rightOf(view, 150);
|
|
1028
|
-
assert.match(pane, /\[x\] #12/);
|
|
1029
|
-
assert.match(pane, /\[x\] #14/);
|
|
1059
|
+
assert.match(pane, /\[x\] #12 Tw/);
|
|
1060
|
+
assert.match(pane, /\[x\] #14 Fo/);
|
|
1030
1061
|
view.handleInput('down');
|
|
1031
1062
|
view.handleInput('space');
|
|
1032
1063
|
view.handleInput('n');
|
|
1033
|
-
|
|
1034
|
-
view.handleInput('
|
|
1064
|
+
await tick();
|
|
1065
|
+
view.handleInput('down');
|
|
1066
|
+
view.handleInput('down');
|
|
1067
|
+
view.handleInput('space');
|
|
1035
1068
|
view.handleInput('enter');
|
|
1036
1069
|
pane = rightOf(view, 150);
|
|
1037
|
-
assert.match(pane, /\[x\] #77/, 'the
|
|
1070
|
+
assert.match(pane, /\[x\] #77 Se/, 'the picked number is part of the draft');
|
|
1038
1071
|
view.handleInput('ctrl+s');
|
|
1039
1072
|
await tick();
|
|
1040
1073
|
assert.deepEqual(applied, [{ number: 6, delta: { add: [77], remove: [14] } }]);
|
|
1041
1074
|
assert.equal(view.state.mode, 'list');
|
|
1042
1075
|
});
|
|
1043
1076
|
|
|
1077
|
+
test('T20: the linked toggles name each issue by number and title', async () => {
|
|
1078
|
+
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1079
|
+
const candidates = candidateSource([{
|
|
1080
|
+
rows: [
|
|
1081
|
+
{ number: 61, title: 'TEMP: rail check 1', state: 'open' },
|
|
1082
|
+
{ number: 77, title: 'Another linked issue', state: 'open' },
|
|
1083
|
+
],
|
|
1084
|
+
hasMore: false,
|
|
1085
|
+
cursor: null,
|
|
1086
|
+
}]);
|
|
1087
|
+
const { view } = makeView({
|
|
1088
|
+
loadPullRequestPage: source.load,
|
|
1089
|
+
loadPullRequest: (number) => ({
|
|
1090
|
+
ok: true,
|
|
1091
|
+
pullRequest: pullRequest(number, { permissions: EDITABLE, linkedIssues: [61, 77] }),
|
|
1092
|
+
comments: [],
|
|
1093
|
+
}),
|
|
1094
|
+
loadIssueCandidates: candidates.load,
|
|
1095
|
+
});
|
|
1096
|
+
await tick();
|
|
1097
|
+
view.handleInput('i');
|
|
1098
|
+
await tick();
|
|
1099
|
+
const pane = rightOf(view, 150);
|
|
1100
|
+
assert.match(pane, /\[x\] #61 TEMP: rail check 1/, 'the toggle is `#N title`, never a bare number');
|
|
1101
|
+
assert.match(pane, /\[x\] #77 Another linked issue/);
|
|
1102
|
+
assert.equal(candidates.calls.length, 1, 'the titles are read once when the editor opens');
|
|
1103
|
+
assert.deepEqual(candidates.calls[0], { after: null, pageSize: 18 });
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
test('T20: n lists the repository issues with the linked ones first and checked', async () => {
|
|
1107
|
+
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1108
|
+
// The seam answers hotspots first; the linked numbers must still come first.
|
|
1109
|
+
const candidates = candidateSource([{
|
|
1110
|
+
rows: [
|
|
1111
|
+
{ number: 20, title: 'Newest open issue', state: 'open' },
|
|
1112
|
+
{ number: 12, title: 'Twelve', state: 'open' },
|
|
1113
|
+
{ number: 14, title: 'Fourteen', state: 'open' },
|
|
1114
|
+
],
|
|
1115
|
+
hasMore: false,
|
|
1116
|
+
cursor: null,
|
|
1117
|
+
}]);
|
|
1118
|
+
const { view } = makeView({
|
|
1119
|
+
loadPullRequestPage: source.load,
|
|
1120
|
+
loadPullRequest: (number) => ({ ok: true, pullRequest: pullRequest(number, { permissions: EDITABLE }), comments: [] }),
|
|
1121
|
+
loadIssueCandidates: candidates.load,
|
|
1122
|
+
});
|
|
1123
|
+
await tick();
|
|
1124
|
+
view.handleInput('i');
|
|
1125
|
+
await tick();
|
|
1126
|
+
view.handleInput('n');
|
|
1127
|
+
await tick();
|
|
1128
|
+
const pane = rightRows(view, 150).join('\n');
|
|
1129
|
+
assert.match(pane, /\[x\] #12 Twelve/);
|
|
1130
|
+
assert.match(pane, /\[x\] #14 Fourteen/);
|
|
1131
|
+
assert.match(pane, /\[ \] #20 Newest open issue/);
|
|
1132
|
+
const linkedAt = pane.indexOf('[x] #12');
|
|
1133
|
+
const otherAt = pane.indexOf('[ ] #20');
|
|
1134
|
+
assert.ok(linkedAt >= 0 && otherAt > linkedAt, 'the linked issues are painted before the rest');
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
test('T20: the candidate list reads the next page as it scrolls', async () => {
|
|
1138
|
+
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1139
|
+
const row = (number) => ({ number, title: `Issue ${number}`, state: 'open' });
|
|
1140
|
+
const candidates = candidateSource([
|
|
1141
|
+
{ rows: [1, 2, 3, 4].map(row), hasMore: true, cursor: 'c4' },
|
|
1142
|
+
{ rows: [5, 6, 7, 8].map(row), hasMore: false, cursor: null },
|
|
1143
|
+
]);
|
|
1144
|
+
const { view } = makeView({
|
|
1145
|
+
loadPullRequestPage: source.load,
|
|
1146
|
+
loadPullRequest: (number) => ({ ok: true, pullRequest: pullRequest(number, { permissions: EDITABLE, linkedIssues: [] }), comments: [] }),
|
|
1147
|
+
loadIssueCandidates: candidates.load,
|
|
1148
|
+
rows: 10,
|
|
1149
|
+
});
|
|
1150
|
+
await tick();
|
|
1151
|
+
view.handleInput('i');
|
|
1152
|
+
await tick();
|
|
1153
|
+
view.handleInput('n');
|
|
1154
|
+
await tick();
|
|
1155
|
+
assert.equal(candidates.calls.length, 1, 'the editor open read the first page once');
|
|
1156
|
+
assert.equal(candidates.calls[0].after, null);
|
|
1157
|
+
assert.equal(candidates.calls[0].pageSize, 4, 'a page is the pane row budget');
|
|
1158
|
+
view.handleInput('ctrl+j');
|
|
1159
|
+
await tick();
|
|
1160
|
+
assert.equal(candidates.calls.length, 2, 'scrolling down reads the next page');
|
|
1161
|
+
assert.equal(candidates.calls[1].after, 'c4', 'the continuation is the previous page cursor');
|
|
1162
|
+
assert.match(rightOf(view, 150, 10), /#5 Issue 5/, 'the next page joins the list');
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1165
|
+
test('T20: space toggles a candidate, enter keeps it and esc discards it', async () => {
|
|
1166
|
+
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1167
|
+
const candidates = candidateSource([{
|
|
1168
|
+
rows: [
|
|
1169
|
+
{ number: 12, title: 'Twelve', state: 'open' },
|
|
1170
|
+
{ number: 20, title: 'Twenty', state: 'open' },
|
|
1171
|
+
],
|
|
1172
|
+
hasMore: false,
|
|
1173
|
+
cursor: null,
|
|
1174
|
+
}]);
|
|
1175
|
+
const { view } = makeView({
|
|
1176
|
+
loadPullRequestPage: source.load,
|
|
1177
|
+
loadPullRequest: (number) => ({ ok: true, pullRequest: pullRequest(number, { permissions: EDITABLE, linkedIssues: [12] }), comments: [] }),
|
|
1178
|
+
loadIssueCandidates: candidates.load,
|
|
1179
|
+
});
|
|
1180
|
+
await tick();
|
|
1181
|
+
view.handleInput('i');
|
|
1182
|
+
await tick();
|
|
1183
|
+
view.handleInput('n');
|
|
1184
|
+
await tick();
|
|
1185
|
+
view.handleInput('down');
|
|
1186
|
+
view.handleInput('space');
|
|
1187
|
+
assert.match(rightOf(view, 150), /\[x\] #20 Twenty/, 'space toggles the focused row');
|
|
1188
|
+
view.handleInput('enter');
|
|
1189
|
+
let pane = rightOf(view, 150);
|
|
1190
|
+
assert.match(pane, /\[x\] #12 Twelve/);
|
|
1191
|
+
assert.match(pane, /\[x\] #20 Twenty/, 'enter keeps the selection back in the toggles');
|
|
1192
|
+
// A second, fresh draft: the list's own pick is discarded on esc.
|
|
1193
|
+
view.handleInput('escape');
|
|
1194
|
+
view.handleInput('i');
|
|
1195
|
+
await tick();
|
|
1196
|
+
view.handleInput('n');
|
|
1197
|
+
await tick();
|
|
1198
|
+
view.handleInput('down');
|
|
1199
|
+
view.handleInput('space');
|
|
1200
|
+
assert.match(rightOf(view, 150), /\[x\] #20 Twenty/);
|
|
1201
|
+
view.handleInput('escape');
|
|
1202
|
+
pane = rightOf(view, 150);
|
|
1203
|
+
assert.match(pane, /\[x\] #12 Twelve/);
|
|
1204
|
+
assert.doesNotMatch(pane, /#20/, 'esc leaves the list without keeping the pick');
|
|
1205
|
+
});
|
|
1206
|
+
|
|
1207
|
+
test('T20: a failed candidate read keeps the toggles and paints the error', async () => {
|
|
1208
|
+
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1209
|
+
const candidates = candidateSource([], { fail: 'rate limited' });
|
|
1210
|
+
const { view } = makeView({
|
|
1211
|
+
loadPullRequestPage: source.load,
|
|
1212
|
+
loadPullRequest: (number) => ({ ok: true, pullRequest: pullRequest(number, { permissions: EDITABLE }), comments: [] }),
|
|
1213
|
+
loadIssueCandidates: candidates.load,
|
|
1214
|
+
});
|
|
1215
|
+
await tick();
|
|
1216
|
+
view.handleInput('i');
|
|
1217
|
+
await tick();
|
|
1218
|
+
let pane = rightOf(view, 150);
|
|
1219
|
+
assert.match(pane, /\[x\] #12/);
|
|
1220
|
+
assert.match(pane, /\[x\] #14/);
|
|
1221
|
+
assert.match(pane, /issues unreadable: rate limited/);
|
|
1222
|
+
view.handleInput('n');
|
|
1223
|
+
await tick();
|
|
1224
|
+
pane = rightOf(view, 150);
|
|
1225
|
+
assert.match(pane, /issues unreadable: rate limited/);
|
|
1226
|
+
assert.match(pane, /\[x\] #12/, 'the linked toggles are still part of the draft');
|
|
1227
|
+
view.handleInput('escape');
|
|
1228
|
+
pane = rightOf(view, 150);
|
|
1229
|
+
assert.match(pane, /\[x\] #12/);
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
test('T20: picked candidates save ONE delta and never duplicate a linked number', async () => {
|
|
1233
|
+
const applied = [];
|
|
1234
|
+
const source = pageSource({ mine: [pullRequest(6)], review: [], involved: [] });
|
|
1235
|
+
const candidates = candidateSource([{
|
|
1236
|
+
rows: [
|
|
1237
|
+
{ number: 12, title: 'Twelve', state: 'open' },
|
|
1238
|
+
{ number: 20, title: 'Twenty', state: 'open' },
|
|
1239
|
+
],
|
|
1240
|
+
hasMore: false,
|
|
1241
|
+
cursor: null,
|
|
1242
|
+
}]);
|
|
1243
|
+
const { view } = makeView({
|
|
1244
|
+
loadPullRequestPage: source.load,
|
|
1245
|
+
loadPullRequest: (number) => ({ ok: true, pullRequest: pullRequest(number, { permissions: EDITABLE, linkedIssues: [12] }), comments: [] }),
|
|
1246
|
+
loadIssueCandidates: candidates.load,
|
|
1247
|
+
actions: { editLinkedIssues: (number, delta) => { applied.push({ number, delta }); return { ok: true }; } },
|
|
1248
|
+
});
|
|
1249
|
+
await tick();
|
|
1250
|
+
view.handleInput('i');
|
|
1251
|
+
await tick();
|
|
1252
|
+
view.handleInput('n');
|
|
1253
|
+
await tick();
|
|
1254
|
+
view.handleInput('space');
|
|
1255
|
+
view.handleInput('space');
|
|
1256
|
+
view.handleInput('down');
|
|
1257
|
+
view.handleInput('space');
|
|
1258
|
+
view.handleInput('space');
|
|
1259
|
+
view.handleInput('space');
|
|
1260
|
+
view.handleInput('enter');
|
|
1261
|
+
view.handleInput('ctrl+s');
|
|
1262
|
+
await tick();
|
|
1263
|
+
assert.deepEqual(applied, [{ number: 6, delta: { add: [20], remove: [] } }]);
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1044
1266
|
test('o opens the pull request on the web and r asks the list to be read again', async () => {
|
|
1045
1267
|
const opened = [];
|
|
1046
1268
|
const source = pageSource({ mine: [pullRequest(8)], review: [], involved: [] });
|
|
@@ -1460,3 +1682,126 @@ describe('prs view editors re-check their capability at save time (S2)', () => {
|
|
|
1460
1682
|
});
|
|
1461
1683
|
}
|
|
1462
1684
|
});
|
|
1685
|
+
|
|
1686
|
+
// S6 follow-up: the same link geometry answers the pointer. Pi's TUI delivers
|
|
1687
|
+
// `type: "move"` events to `handleMouse`, so hovering a linked issue number
|
|
1688
|
+
// paints exactly that number in the role the rail gives a hovered row, moving
|
|
1689
|
+
// off clears it, and a repaint happens only when the target actually changes.
|
|
1690
|
+
describe('S6: a move over a linked issue number highlights it', () => {
|
|
1691
|
+
// A theme that RECORDS which role each string was painted with and paints
|
|
1692
|
+
// every role with its own SGR code, so a frame can be read for the role
|
|
1693
|
+
// behind a token instead of an eyeballed colour.
|
|
1694
|
+
const ROLE_SGR = { accent: 96, customMessageLabel: 33, muted: 90, dim: 2, border: 34, error: 91, text: 39 };
|
|
1695
|
+
function recordingTheme() {
|
|
1696
|
+
const calls = [];
|
|
1697
|
+
const code = (role) => ROLE_SGR[role] ?? 95;
|
|
1698
|
+
return {
|
|
1699
|
+
calls,
|
|
1700
|
+
fg(role, text) {
|
|
1701
|
+
calls.push({ role, text: String(text) });
|
|
1702
|
+
return `\x1b[${code(role)}m${text}\x1b[0m`;
|
|
1703
|
+
},
|
|
1704
|
+
bold(text) {
|
|
1705
|
+
calls.push({ role: 'bold', text: String(text) });
|
|
1706
|
+
return `\x1b[1m${text}\x1b[22m`;
|
|
1707
|
+
},
|
|
1708
|
+
bg(role, text) {
|
|
1709
|
+
calls.push({ role: `bg:${role}`, text: String(text) });
|
|
1710
|
+
return String(text);
|
|
1711
|
+
},
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
function moveMouse(view, cell, offset = 0) {
|
|
1716
|
+
return view.handleMouse({
|
|
1717
|
+
type: 'move',
|
|
1718
|
+
button: 'none',
|
|
1719
|
+
x: cell.x + offset,
|
|
1720
|
+
y: cell.y,
|
|
1721
|
+
width: cell.widthCells,
|
|
1722
|
+
height: cell.rows,
|
|
1723
|
+
});
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
function hoverView() {
|
|
1727
|
+
const theme = recordingTheme();
|
|
1728
|
+
const opened = [];
|
|
1729
|
+
const source = pageSource({ mine: [pullRequest(87)], review: [], involved: [] });
|
|
1730
|
+
const made = makeView({
|
|
1731
|
+
loadPullRequestPage: source.load,
|
|
1732
|
+
theme,
|
|
1733
|
+
actions: { openLinked: (target) => opened.push(target) },
|
|
1734
|
+
});
|
|
1735
|
+
return { view: made.view, paints: made.paints, theme, opened };
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
// The roles the LAST render asked for, so an assertion is about this frame.
|
|
1739
|
+
function hoveredNumbers(view, theme, width = 150) {
|
|
1740
|
+
const mark = theme.calls.length;
|
|
1741
|
+
const lines = view.render(width);
|
|
1742
|
+
const roles = theme.calls.slice(mark)
|
|
1743
|
+
.filter((call) => call.role === 'accent' && /^#\d+$/.test(call.text))
|
|
1744
|
+
.map((call) => call.text);
|
|
1745
|
+
return { roles, lines };
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
test('a move over one number paints exactly that range, and moving off clears it', async () => {
|
|
1749
|
+
const { view, theme } = hoverView();
|
|
1750
|
+
await tick();
|
|
1751
|
+
const linked = paneCell(view, 150, '#12');
|
|
1752
|
+
assert.deepEqual(moveMouse(view, linked), { handled: true, render: true },
|
|
1753
|
+
'the move is consumed and asks for a repaint');
|
|
1754
|
+
|
|
1755
|
+
let hovered = hoveredNumbers(view, theme);
|
|
1756
|
+
assert.deepEqual(hovered.roles, ['#12'], 'only the hovered number takes the hover role');
|
|
1757
|
+
const row = hovered.lines.find((line) => strip(line).includes('linked issues:'));
|
|
1758
|
+
assert.ok(row.includes('\x1b[96m#12'), 'the hovered number is painted with the accent role');
|
|
1759
|
+
assert.ok(!row.includes('\x1b[96m#14'), 'the other number keeps its plain text');
|
|
1760
|
+
assert.match(strip(row), /linked issues: #12, #14/, 'painting never changes the row the click expects');
|
|
1761
|
+
|
|
1762
|
+
const off = paneCell(view, 150, 'linked issues:');
|
|
1763
|
+
assert.deepEqual(moveMouse(view, off), { handled: true, render: true },
|
|
1764
|
+
'moving onto the row label is a change of target');
|
|
1765
|
+
hovered = hoveredNumbers(view, theme);
|
|
1766
|
+
assert.deepEqual(hovered.roles, [], 'nothing is highlighted once the pointer leaves the number');
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1769
|
+
test('a move to another number moves the highlight with it', async () => {
|
|
1770
|
+
const { view, theme } = hoverView();
|
|
1771
|
+
await tick();
|
|
1772
|
+
assert.deepEqual(moveMouse(view, paneCell(view, 150, '#12')), { handled: true, render: true });
|
|
1773
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, ['#12']);
|
|
1774
|
+
assert.deepEqual(moveMouse(view, paneCell(view, 150, '#14')), { handled: true, render: true });
|
|
1775
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, ['#14'], 'the highlight follows the pointer');
|
|
1776
|
+
});
|
|
1777
|
+
|
|
1778
|
+
test('the same target twice does not repaint, and a move outside clears the hover', async () => {
|
|
1779
|
+
const { view, theme, paints } = hoverView();
|
|
1780
|
+
await tick();
|
|
1781
|
+
const linked = paneCell(view, 150, '#12');
|
|
1782
|
+
moveMouse(view, linked);
|
|
1783
|
+
const painted = paints.length;
|
|
1784
|
+
assert.deepEqual(moveMouse(view, linked), { handled: true, render: false },
|
|
1785
|
+
'the hovered target did not change, so no repaint is asked for');
|
|
1786
|
+
assert.equal(paints.length, painted, 'and none is issued');
|
|
1787
|
+
|
|
1788
|
+
assert.deepEqual(moveMouse(view, { ...linked, x: 3 }), { handled: true, render: true },
|
|
1789
|
+
'a move onto the list column lands on no link and clears the hover');
|
|
1790
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, []);
|
|
1791
|
+
assert.deepEqual(view.handleMouse({
|
|
1792
|
+
type: 'move', button: 'none', x: linked.x, y: linked.y, width: 100, height: linked.rows,
|
|
1793
|
+
}), { handled: true, render: false }, 'a move from another frame geometry lands nowhere');
|
|
1794
|
+
});
|
|
1795
|
+
|
|
1796
|
+
test('the same geometry serves the click and the hover', async () => {
|
|
1797
|
+
const { view, opened } = hoverView();
|
|
1798
|
+
await tick();
|
|
1799
|
+
const linked = paneCell(view, 150, '#12');
|
|
1800
|
+
assert.deepEqual(moveMouse(view, linked), { handled: true, render: true });
|
|
1801
|
+
// The cell the pointer highlighted is exactly the cell that opens #12.
|
|
1802
|
+
assert.deepEqual(click(view, linked), { handled: true, render: false });
|
|
1803
|
+
assert.deepEqual(opened, [{ kind: 'issue', number: 12 }]);
|
|
1804
|
+
assert.deepEqual(moveMouse(view, linked, 3), { handled: true, render: true },
|
|
1805
|
+
'a move onto the separator clears the hover');
|
|
1806
|
+
});
|
|
1807
|
+
});
|
|
@@ -952,12 +952,179 @@ test('an empty prompt draws no card: the host\'s own nothing comes back', () =>
|
|
|
952
952
|
assert.deepEqual(component.render(60), []);
|
|
953
953
|
});
|
|
954
954
|
|
|
955
|
-
|
|
955
|
+
// ---- S1 (prompt-card-fix): the heading's clock, in grey beside the name ----
|
|
956
|
+
|
|
957
|
+
/** Local 24-hour `HH:MM`, zero padded: the clock the heading is expected to carry. */
|
|
958
|
+
const localClock = (instant) => `${String(instant.getHours()).padStart(2, '0')}:${String(instant.getMinutes()).padStart(2, '0')}`;
|
|
959
|
+
|
|
960
|
+
/** The `HH:MM` a heading row draws after its separator, read from the row's own cells. */
|
|
961
|
+
function headingClock(row) {
|
|
962
|
+
const line = cells(row);
|
|
963
|
+
const dot = line.findIndex((cell) => cell.char === '·');
|
|
964
|
+
if (dot < 0) return undefined;
|
|
965
|
+
return line.slice(dot + 2, dot + 7).map((cell) => cell.char).join('');
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
test('S1: a component with a timestamp heads ✿ You · <local HH:MM>, and the clock is muted', () => {
|
|
956
969
|
publishBridge(ACTIVITY_ANSWER);
|
|
957
|
-
|
|
970
|
+
const paint = roleTheme();
|
|
971
|
+
install({ seams: { paint } });
|
|
972
|
+
// The instant the host sets on a prompt rebuilt from a session entry: an ISO string in UTC.
|
|
973
|
+
const at = '2026-11-23T19:12:59Z';
|
|
974
|
+
const expected = localClock(new Date(at));
|
|
958
975
|
const component = promptComponent();
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
assert.
|
|
976
|
+
component.timestamp = at;
|
|
977
|
+
const rows = component.render(60);
|
|
978
|
+
const head = unpaint(rows[0]);
|
|
979
|
+
assert.match(head, /^╭─ ✿ You · \d{2}:\d{2} /u, 'the name, the separator and the clock, on the frame');
|
|
980
|
+
assert.ok(head.includes(`✿ You · ${expected}`), `the clock is the local HH:MM of that instant: ${expected}`);
|
|
981
|
+
assert.equal(headingClock(rows[0]), expected, 'five clock columns, zero padded, no seconds');
|
|
982
|
+
// The role actually painted on the separator and on each clock column.
|
|
983
|
+
const line = cells(rows[0]);
|
|
984
|
+
const dot = line.findIndex((cell) => cell.char === '·');
|
|
985
|
+
assert.equal(line[dot].code, ROLE_CODE.muted, 'the separator wears the muted role');
|
|
986
|
+
for (const cell of line.slice(dot + 2, dot + 7)) {
|
|
987
|
+
assert.equal(cell.code, ROLE_CODE.muted, `"${cell.char}" of the clock is painted muted`);
|
|
988
|
+
}
|
|
989
|
+
const mark = line.find((cell) => cell.char === '✿');
|
|
990
|
+
assert.equal(mark.code, ROLE_CODE.accent, 'the mark still wears the accent with the name');
|
|
991
|
+
});
|
|
992
|
+
|
|
993
|
+
test('S1: without a timestamp the first-paint clock is used, unchanged on every later paint', () => {
|
|
994
|
+
publishBridge(ACTIVITY_ANSWER);
|
|
995
|
+
install();
|
|
996
|
+
const realNow = Date.now;
|
|
997
|
+
try {
|
|
998
|
+
Date.now = () => new Date(2026, 0, 2, 9, 7, 30).getTime();
|
|
999
|
+
const component = promptComponent();
|
|
1000
|
+
const first = unpaint(component.render(60)[0]);
|
|
1001
|
+
assert.ok(first.includes('✿ You · 09:07'), `the clock of the first paint: ${first}`);
|
|
1002
|
+
// The clock moves on: a later frame keeps the arrival time, it never drifts.
|
|
1003
|
+
Date.now = () => new Date(2026, 0, 2, 17, 45, 0).getTime();
|
|
1004
|
+
const later = unpaint(component.render(60)[0]);
|
|
1005
|
+
assert.equal(later, first, 'a later paint is the same heading, to the cell');
|
|
1006
|
+
// A component built now has its OWN arrival time, captured on its own first paint.
|
|
1007
|
+
const other = promptComponent();
|
|
1008
|
+
assert.ok(unpaint(other.render(60)[0]).includes('✿ You · 17:45'), 'each prompt keeps its own first-paint clock');
|
|
1009
|
+
assert.ok(unpaint(other.render(60)[0]).includes('✿ You · 17:45'), 'and it holds on the next paint too');
|
|
1010
|
+
} finally {
|
|
1011
|
+
Date.now = realNow;
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
|
|
1015
|
+
test('S1: a component with neither a timestamp nor a clock shows ✿ You alone, inventing nothing', () => {
|
|
1016
|
+
publishBridge(ACTIVITY_ANSWER);
|
|
1017
|
+
install({ seams: { paint: taggedTheme } });
|
|
1018
|
+
const realNow = Date.now;
|
|
1019
|
+
try {
|
|
1020
|
+
// No clock to read at all, and nothing on the component: the heading is the name.
|
|
1021
|
+
Date.now = () => Number.NaN;
|
|
1022
|
+
const component = promptComponent();
|
|
1023
|
+
const head = component.render(60)[0];
|
|
1024
|
+
assert.ok(head.includes('<accent>✿ You</accent>'), 'the mark and the name wear the title role together');
|
|
1025
|
+
const plain = unpaint(head);
|
|
1026
|
+
assert.match(plain, /^╭─ ✿ You /u, 'the heading is the name alone');
|
|
1027
|
+
assert.equal(plain.includes('·'), false, 'no subtitle separator');
|
|
1028
|
+
assert.doesNotMatch(plain, /\d{1,2}:\d{2}|ago/u, 'no time is invented');
|
|
1029
|
+
// A timestamp nothing can read is no clock either: still nothing invented.
|
|
1030
|
+
const unreadable = promptComponent();
|
|
1031
|
+
unreadable.timestamp = 'yesterday';
|
|
1032
|
+
assert.equal(unpaint(unreadable.render(60)[0]).includes('·'), false, 'an unreadable timestamp invents no clock');
|
|
1033
|
+
} finally {
|
|
1034
|
+
Date.now = realNow;
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
|
|
1038
|
+
// ---- S2 (prompt-card-fix): a restored session repaints — once per install ----
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* The bridge a repaint assertion needs: the published object every surface here reads, with a
|
|
1042
|
+
* `requestRepaint` recorder and the gate's own reader. `extra` replaces a member per case.
|
|
1043
|
+
*/
|
|
1044
|
+
function repaintBridge(extra = {}) {
|
|
1045
|
+
const api = fixture.defaultBridge().api;
|
|
1046
|
+
const state = { repaints: 0 };
|
|
1047
|
+
api.requestRepaint = () => {
|
|
1048
|
+
state.repaints += 1;
|
|
1049
|
+
};
|
|
1050
|
+
api.resolveToolDesignSelection = () => ACTIVITY_ANSWER;
|
|
1051
|
+
Object.assign(api, extra);
|
|
1052
|
+
return { api, state };
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Load this extension with one published bridge and drive the session that owns the deferred
|
|
1057
|
+
* install — the only path that knows a session is live. Answers the host class and the hooks, so
|
|
1058
|
+
* a test can watch the prototype and a paint.
|
|
1059
|
+
*/
|
|
1060
|
+
async function loadPromptCardSession(bridgeApi) {
|
|
1061
|
+
const previous = globalThis[BRIDGE_API_SLOT];
|
|
1062
|
+
globalThis[BRIDGE_API_SLOT] = bridgeApi;
|
|
1063
|
+
class Host {
|
|
1064
|
+
render(width) {
|
|
1065
|
+
return [`native ${width}`];
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
const native = Host.prototype.render;
|
|
1069
|
+
const { hooks } = await loadExtensionModule(() => ({ UserMessageComponent: Host }));
|
|
1070
|
+
const emit = extensionSession(hooks);
|
|
1071
|
+
const shutdown = async () => {
|
|
1072
|
+
await emit('session_shutdown');
|
|
1073
|
+
if (previous === undefined) delete globalThis[BRIDGE_API_SLOT];
|
|
1074
|
+
else globalThis[BRIDGE_API_SLOT] = previous;
|
|
1075
|
+
};
|
|
1076
|
+
return { Host, native, emit, shutdown };
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
test('S2: a successful install asks the bridge for exactly one repaint, and no paint asks again', async () => {
|
|
1080
|
+
const bridge = repaintBridge();
|
|
1081
|
+
const session = await loadPromptCardSession(bridge.api);
|
|
1082
|
+
try {
|
|
1083
|
+
await session.emit('session_start');
|
|
1084
|
+
await drain();
|
|
1085
|
+
assert.notEqual(session.Host.prototype.render, session.native, 'the class is patched by the live session');
|
|
1086
|
+
assert.equal(bridge.state.repaints, 1, 'the restored transcript is asked to repaint once');
|
|
1087
|
+
// Painting is what the request produced: it never asks for another repaint itself.
|
|
1088
|
+
const component = new session.Host();
|
|
1089
|
+
component.render(60);
|
|
1090
|
+
component.render(62);
|
|
1091
|
+
assert.equal(bridge.state.repaints, 1, 'a paint requests none, and a steady frame neither');
|
|
1092
|
+
// A second `session_start` is a re-install: it asks again, exactly once.
|
|
1093
|
+
await session.emit('session_start');
|
|
1094
|
+
await drain();
|
|
1095
|
+
assert.equal(bridge.state.repaints, 2, 'the re-install path asks for its own single repaint');
|
|
1096
|
+
} finally {
|
|
1097
|
+
await session.shutdown();
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
test('S2: an install the gate never armed, and a bridge with no requestRepaint, ask for none', async () => {
|
|
1102
|
+
// (a) The bridge refuses the design registration, so the install was never armed: no request.
|
|
1103
|
+
const refused = repaintBridge({
|
|
1104
|
+
registerToolDesign: () => {
|
|
1105
|
+
throw new Error('this bridge refuses the activity design');
|
|
1106
|
+
},
|
|
1107
|
+
});
|
|
1108
|
+
const ungated = await loadPromptCardSession(refused.api);
|
|
1109
|
+
try {
|
|
1110
|
+
await ungated.emit('session_start');
|
|
1111
|
+
await drain();
|
|
1112
|
+
assert.equal(ungated.Host.prototype.render, ungated.native, 'nothing was installed for a gated line');
|
|
1113
|
+
assert.equal(refused.state.repaints, 0, 'an install that never happened asks for nothing');
|
|
1114
|
+
} finally {
|
|
1115
|
+
await ungated.shutdown();
|
|
1116
|
+
}
|
|
1117
|
+
// (b) The member is optional: the install succeeds and no member is there to call.
|
|
1118
|
+
const absent = repaintBridge({});
|
|
1119
|
+
delete absent.api.requestRepaint;
|
|
1120
|
+
const memberless = await loadPromptCardSession(absent.api);
|
|
1121
|
+
try {
|
|
1122
|
+
assert.equal('requestRepaint' in absent.api, false, 'the published bridge carries no such member');
|
|
1123
|
+
await memberless.emit('session_start');
|
|
1124
|
+
await drain();
|
|
1125
|
+
assert.notEqual(memberless.Host.prototype.render, memberless.native, 'the install still happened');
|
|
1126
|
+
assert.equal(absent.state.repaints, 0, 'and nothing was asked for');
|
|
1127
|
+
} finally {
|
|
1128
|
+
await memberless.shutdown();
|
|
1129
|
+
}
|
|
963
1130
|
});
|