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 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");
258 + text:
JSON.
stringify({
263 + summary:
"already current",
271 + getModel: ((provider
: string, id
: string)
=> ({ provider, id }))
as never,
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",
283 + h.notifications.
some((n)
=> n.message.
includes(
"changed while updating")),
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 178 +interface PulseApplyResult {
179 + applied
: PulseUpdate[];
180 + alreadyCurrent
: PulseUpdate[];
178 183 interface PulsePersistedState {
180 185 lastRunAt
: number;
409 414 docs: LoadedPulseDoc[],
410 415 updates: 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);
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");
434 + return { applied, alreadyCurrent };
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);
908 921 state.lastResult
= e
instanceof Error ? e.message
: String(e);
928 941 `Pulse: updated ${applied.length} doc(s)\n${lines.join("\n")}`,
944 + }
else if (alreadyCurrent.
length > 0) {
945 + state.lastResult
= "already current";
947 + `Pulse: already current: ${alreadyCurrent.map((u) => displayText(u.path)).join(", ")}`,
931 950 }
else if (missingAuthModels.
length > 0) {
932 951 state.lastResult
= "missing auth";