pi-odd-worktree 3.11.1 → 3.12.0

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.
@@ -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
- test('the heading is this package\'s card: the accent name, no subtitle and no time', () => {
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
- install({ seams: { paint: taggedTheme } });
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
- const head = component.render(60)[0];
960
- assert.ok(head.includes('<accent>✿ You</accent>'), 'the mark and the name wear the title role together');
961
- assert.equal(unpaint(head).includes('·'), false, 'no subtitle separator');
962
- assert.doesNotMatch(unpaint(head), /\d{1,2}:\d{2}|ago/u, 'no timestamp: gentle-timestamps owns the clock');
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
  });