repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(pulse): report already-current updates as info

bd5a52514bc18bf73b858ad422e606046d362a9f

Review <review@example.invalid> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

extensions/pulse/__tests__/index.test.ts

Modified
244 244 ).toBe(true);
247 + it("reports an info no-op when the file already matches the proposal", async () => {
248 + const root = cwd();
249 + write(root, "README.md", "old");
250 + writeConfig(root, { documents: [{ path: "README.md" }] });
251 + __setPulseModelClient({
252 + complete: (async () => {
253 + fs.writeFileSync(path.join(root, "README.md"), "new", "utf8");
254 + return {
255 + content: [
257 + type: "text",
258 + text: JSON.stringify({
259 + updates: [
261 + path: "README.md",
262 + content: "new",
263 + summary: "already current",
264 + },
265 + ],
266 + }),
267 + },
268 + ],
269 + };
270 + }) as never,
271 + getModel: ((provider: string, id: string) => ({ provider, id })) as never,
272 + });
273 + const h = harness(root);
275 + await h.commands.get("pulse").handler("force", h.ctx);
277 + expect(fs.readFileSync(path.join(root, "README.md"), "utf8")).toBe("new");
278 + expect(h.notifications).toContainEqual({
279 + message: "Pulse: already current: README.md",
280 + level: "info",
281 + });
282 + expect(
283 + h.notifications.some((n) => n.message.includes("changed while updating")),
284 + ).toBe(false);
285 + });
247 287 it("persists run state through the fresh command context, not captured pi", async () => {
248 288 const root = cwd();
249 289 write(root, "README.md", "old");

extensions/pulse/index.ts

Modified
175 175 summary: string;
178 +interface PulseApplyResult {
179 + applied: PulseUpdate[];
180 + alreadyCurrent: PulseUpdate[];
178 183 interface PulsePersistedState {
179 184 version: 1;
180 185 lastRunAt: number;
408 413 cwd: string,
409 414 docs: LoadedPulseDoc[],
410 415 updates: PulseUpdate[],
411 -): PulseUpdate[] {
416 +): PulseApplyResult {
412 417 const byPath = new Map(docs.map((d) => [d.path, d]));
418 + const applied: PulseUpdate[] = [];
419 + const alreadyCurrent: PulseUpdate[] = [];
413 420 for (const update of updates) {
414 421 const doc = byPath.get(update.path);
415 422 if (!doc) throw new Error(`update path not allowed: ${update.path}`);
416 423 assertRealPathInside(cwd, doc.absPath);
417 424 const current = fs.readFileSync(doc.absPath, "utf-8");
425 + if (current === update.content) {
426 + alreadyCurrent.push(update);
427 + continue;
418 429 if (sha256(current) !== doc.hash)
419 430 throw new Error(`changed while updating: ${update.path}`);
431 + fs.writeFileSync(doc.absPath, update.content, "utf-8");
432 + applied.push(update);
421 - for (const update of updates) {
422 - fs.writeFileSync(byPath.get(update.path)?.absPath, update.content, "utf-8");
424 - return updates;
434 + return { applied, alreadyCurrent };
427 437 // ============================================================================
870 880 const byPath = new Map(loadedDocs.map((d) => [d.path, d]));
871 881 const missingAuthModels: string[] = [];
872 882 const applied: PulseUpdate[] = [];
883 + const alreadyCurrent: PulseUpdate[] = [];
873 884 let failed = false;
874 885 let skipped = false;
903 914 if (ticket !== generation) return;
904 915 if (proposed.length > 0 && updates.length === 0) skipped = true;
905 - applied.push(...applyDocUpdates(runCwd, loadedGroup, updates));
916 + const result = applyDocUpdates(runCwd, loadedGroup, updates);
917 + applied.push(...result.applied);
918 + alreadyCurrent.push(...result.alreadyCurrent);
906 919 } catch (e) {
907 920 failed = true;
908 921 state.lastResult = e instanceof Error ? e.message : String(e);
928 941 `Pulse: updated ${applied.length} doc(s)\n${lines.join("\n")}`,
929 942 "info",
944 + } else if (alreadyCurrent.length > 0) {
945 + state.lastResult = "already current";
946 + ctx.ui.notify(
947 + `Pulse: already current: ${alreadyCurrent.map((u) => displayText(u.path)).join(", ")}`,
948 + "info",
949 + );
931 950 } else if (missingAuthModels.length > 0) {
932 951 state.lastResult = "missing auth";
933 952 ctx.ui.notify(