Skip to content

Commit bb06afa

Browse files
lint: biome format/import-order drift from the merge-conflict resolutions in rust-mode-transform
Co-authored-by: Alfonso <alfonso-magic-context@users.noreply.github.com>
1 parent 34f42b5 commit bb06afa

2 files changed

Lines changed: 112 additions & 54 deletions

File tree

‎packages/plugin/src/hooks/magic-context/rust-mode-transform.test.ts‎

Lines changed: 109 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
openDatabase,
2424
} from "../../features/magic-context/storage-db";
2525
import { getOrCreateSessionMeta } from "../../features/magic-context/storage-meta";
26-
import { bumpProjectMemoryEpoch } from "../../features/magic-context/storage-project-state";
2726
import {
2827
addTrailingBlankDecisions,
2928
armThinkingBindingRecovery,
@@ -36,6 +35,7 @@ import {
3635
resetEmergencyRecoveryRegistryForTest,
3736
setPersistedCompactionMarkerState,
3837
} from "../../features/magic-context/storage-meta-persisted";
38+
import { bumpProjectMemoryEpoch } from "../../features/magic-context/storage-project-state";
3939
import {
4040
scheduleOpenCodeTransformDecisionWrite,
4141
__test as transformDecisionTest,
@@ -909,7 +909,9 @@ describe("Rust mode authority adapter", () => {
909909
const output = { messages: [...input] as unknown[] };
910910
await restarted.run(sessionId, input, output, restartMeta);
911911
expect(servedPrefixSha(output.messages)).toBe(stableSha);
912-
expect(JSON.stringify(output.messages)).not.toContain("published historian compartment");
912+
expect(JSON.stringify(output.messages)).not.toContain(
913+
"published historian compartment",
914+
);
913915
expect(restarted.getState(sessionId).lkgRepresentationFrozen).toBe(true);
914916
}
915917

@@ -1390,7 +1392,9 @@ describe("Rust mode authority adapter", () => {
13901392
firstSync = false;
13911393
throw authoritySeqMismatch(5);
13921394
}
1393-
return method === "transform" ? { decision: "SOFT+", native_messages: native } : { ok: true };
1395+
return method === "transform"
1396+
? { decision: "SOFT+", native_messages: native }
1397+
: { ok: true };
13941398
},
13951399
};
13961400
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });
@@ -1590,7 +1594,9 @@ describe("Rust mode authority adapter", () => {
15901594
call: async ({ method, body }) => {
15911595
methods.push(method);
15921596
if (method === "transform") transformRequest = body as Record<string, unknown>;
1593-
return method === "transform" ? { decision: "SOFT+", native_messages: native } : { ok: true };
1597+
return method === "transform"
1598+
? { decision: "SOFT+", native_messages: native }
1599+
: { ok: true };
15941600
},
15951601
};
15961602
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });
@@ -1633,7 +1639,9 @@ describe("Rust mode authority adapter", () => {
16331639
const moduleClient: RustModeModuleClient = {
16341640
call: async ({ method, body }) => {
16351641
if (method === "transform") requests.push(body as Record<string, unknown>);
1636-
return method === "transform" ? { decision: "SOFT+", native_messages: [] } : { ok: true };
1642+
return method === "transform"
1643+
? { decision: "SOFT+", native_messages: [] }
1644+
: { ok: true };
16371645
},
16381646
};
16391647
const deps = makeDeps(db, moduleClient);
@@ -1690,7 +1698,9 @@ describe("Rust mode authority adapter", () => {
16901698
const moduleClient: RustModeModuleClient = {
16911699
call: async ({ method, body }) => {
16921700
if (method === "transform") transformRequest = body as Record<string, unknown>;
1693-
return method === "transform" ? { decision: "SOFT+", native_messages: makeMessages(sessionId) } : { ok: true };
1701+
return method === "transform"
1702+
? { decision: "SOFT+", native_messages: makeMessages(sessionId) }
1703+
: { ok: true };
16941704
},
16951705
};
16961706
const deps = makeDeps(db, moduleClient);
@@ -1722,7 +1732,9 @@ describe("Rust mode authority adapter", () => {
17221732
const moduleClient: RustModeModuleClient = {
17231733
call: async ({ method, body }) => {
17241734
if (method === "transform") transformRequest = body as Record<string, unknown>;
1725-
return method === "transform" ? { decision: "SOFT+", native_messages: makeMessages(sessionId) } : { ok: true };
1735+
return method === "transform"
1736+
? { decision: "SOFT+", native_messages: makeMessages(sessionId) }
1737+
: { ok: true };
17261738
},
17271739
};
17281740
const deps = makeDeps(db, moduleClient);
@@ -1793,10 +1805,10 @@ describe("Rust mode authority adapter", () => {
17931805
const moduleClient: RustModeModuleClient = {
17941806
call: async ({ method }) =>
17951807
method === "transform"
1796-
? {
1797-
decision: "SOFT+",
1798-
native_messages: makeMessages(sessionId),
1799-
rendered_memory_ids: renderedMemoryIds,
1808+
? {
1809+
decision: "SOFT+",
1810+
native_messages: makeMessages(sessionId),
1811+
rendered_memory_ids: renderedMemoryIds,
18001812
}
18011813
: { ok: true },
18021814
};
@@ -1846,7 +1858,9 @@ describe("Rust mode authority adapter", () => {
18461858
private readonly title = "receiver-bound compartment";
18471859

18481860
async call({ method }: Parameters<RustModeModuleClient["call"]>[0]) {
1849-
return method === "transform" ? { decision: "SOFT+", native_messages: [] } : { ok: true };
1861+
return method === "transform"
1862+
? { decision: "SOFT+", native_messages: [] }
1863+
: { ok: true };
18501864
}
18511865

18521866
async getCompartmentsAfter(_sessionId: string, _afterSequence: number) {
@@ -1897,9 +1911,7 @@ describe("Rust mode authority adapter", () => {
18971911
let mirrorCompleted = false;
18981912
const moduleClient: RustModeModuleClient = {
18991913
call: async ({ method }) =>
1900-
method === "transform"
1901-
? { decision: "HARD", native_messages: [] }
1902-
: { ok: true },
1914+
method === "transform" ? { decision: "HARD", native_messages: [] } : { ok: true },
19031915
getCompartmentsAfter: async () => {
19041916
await mirrorBacklog;
19051917
mirrorCompleted = true;
@@ -1937,7 +1949,9 @@ describe("Rust mode authority adapter", () => {
19371949
const moduleClient: RustModeModuleClient = {
19381950
call: async ({ method, body }) => {
19391951
if (method === "transform") requestBodies.push(body as Record<string, unknown>);
1940-
return method === "transform" ? { decision: "SOFT+", native_messages: [] } : { ok: true };
1952+
return method === "transform"
1953+
? { decision: "SOFT+", native_messages: [] }
1954+
: { ok: true };
19411955
},
19421956
};
19431957
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });
@@ -1970,7 +1984,9 @@ describe("Rust mode authority adapter", () => {
19701984
const moduleClient: RustModeModuleClient = {
19711985
call: async ({ method, body }) => {
19721986
if (method === "transform") requestBody = body as Record<string, unknown>;
1973-
return method === "transform" ? { decision: "SOFT+", native_messages: [] } : { ok: true };
1987+
return method === "transform"
1988+
? { decision: "SOFT+", native_messages: [] }
1989+
: { ok: true };
19741990
},
19751991
};
19761992
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });
@@ -1997,7 +2013,9 @@ describe("Rust mode authority adapter", () => {
19972013
const moduleClient: RustModeModuleClient = {
19982014
call: async ({ method, body }) => {
19992015
if (method === "transform") requestBody = body as Record<string, unknown>;
2000-
return method === "transform" ? { decision: "SOFT+", native_messages: [] } : { ok: true };
2016+
return method === "transform"
2017+
? { decision: "SOFT+", native_messages: [] }
2018+
: { ok: true };
20012019
},
20022020
};
20032021
const deps = makeDeps(db, moduleClient);
@@ -2090,10 +2108,10 @@ describe("Rust mode authority adapter", () => {
20902108
const moduleClient: RustModeModuleClient = {
20912109
call: async ({ method }) =>
20922110
method === "transform"
2093-
? {
2094-
decision: "SOFT+",
2095-
native_messages: [{ role: "assistant", parts: [] }],
2096-
host_directives: {
2111+
? {
2112+
decision: "SOFT+",
2113+
native_messages: [{ role: "assistant", parts: [] }],
2114+
host_directives: {
20972115
channel2_nudge: { text: "drop spent tool output" },
20982116
},
20992117
}
@@ -3568,7 +3586,9 @@ describe("Rust mode authority adapter", () => {
35683586
call: async ({ method }) => {
35693587
if (method === "transform") transformCalls += 1;
35703588
if (shouldFail) throw new Error("daemon unavailable");
3571-
return method === "transform" ? { decision: "SOFT+", native_messages: [{ role: "assistant", parts: [] }] } : { ok: true };
3589+
return method === "transform"
3590+
? { decision: "SOFT+", native_messages: [{ role: "assistant", parts: [] }] }
3591+
: { ok: true };
35723592
},
35733593
};
35743594
const transform = createRustModeTransform(makeDeps(db, moduleClient), {
@@ -4374,47 +4394,75 @@ describe("native output delta", () => {
43744394
installRawProvider(sessionId);
43754395
makeMeta(db, sessionId);
43764396
setPersistedCompactionMarkerState(db, sessionId, {
4377-
boundaryMessageId: "m1", summaryMessageId: "summary",
4378-
compactionPartId: "compaction", summaryPartId: "summary-part",
4379-
boundaryOrdinal: 0, targetEndMessageId: "m1",
4397+
boundaryMessageId: "m1",
4398+
summaryMessageId: "summary",
4399+
compactionPartId: "compaction",
4400+
summaryPartId: "summary-part",
4401+
boundaryOrdinal: 0,
4402+
targetEndMessageId: "m1",
43804403
});
43814404
const message = (id: string): MessageLike => ({
43824405
info: { id, role: "assistant", sessionID: sessionId },
4383-
parts: [{ type: "tool", tool: "work", callID: id, state: {
4384-
status: "completed", input: { action: "settle" }, output: id,
4385-
} }],
4406+
parts: [
4407+
{
4408+
type: "tool",
4409+
tool: "work",
4410+
callID: id,
4411+
state: {
4412+
status: "completed",
4413+
input: { action: "settle" },
4414+
output: id,
4415+
},
4416+
},
4417+
],
43864418
});
4387-
let native: MessageLike[] = [...makeMessages(sessionId), message("settle"), message("board")];
4419+
let native: MessageLike[] = [
4420+
...makeMessages(sessionId),
4421+
message("settle"),
4422+
message("board"),
4423+
];
43884424
let pass = 0;
43894425
const moduleClient: RustModeModuleClient = {
43904426
call: async ({ method, body }) => {
43914427
if (method !== "transform") return { ok: true };
43924428
const request = body as Record<string, unknown>;
4393-
if (pass++ === 0) return {
4394-
decision: "HARD", reason: "epoch_change", scheduler_decision: "defer",
4395-
native_messages: structuredClone(native),
4396-
};
4429+
if (pass++ === 0)
4430+
return {
4431+
decision: "HARD",
4432+
reason: "epoch_change",
4433+
scheduler_decision: "defer",
4434+
native_messages: structuredClone(native),
4435+
};
43974436
const replaceFrom = native.length - 1;
43984437
native = [...native, message(`step-${pass}`)];
4399-
return { decision: "SOFT+", scheduler_decision: "defer", native_messages_delta: {
4400-
after: (request.tail_delta as { after: string }).after,
4401-
replace_from: replaceFrom, messages: structuredClone(native.slice(replaceFrom)),
4402-
} };
4438+
return {
4439+
decision: "SOFT+",
4440+
scheduler_decision: "defer",
4441+
native_messages_delta: {
4442+
after: (request.tail_delta as { after: string }).after,
4443+
replace_from: replaceFrom,
4444+
messages: structuredClone(native.slice(replaceFrom)),
4445+
},
4446+
};
44034447
},
44044448
};
44054449
const deps = makeDeps(db, moduleClient);
44064450
deps.tagger = { assignTag: () => 1 } as unknown as TransformDeps["tagger"];
44074451
const transform = createRustModeTransform(deps, { moduleClient });
4408-
const hash = (messages: unknown[]) => new Bun.CryptoHasher("sha256").update(JSON.stringify(messages)).digest("hex");
4452+
const hash = (messages: unknown[]) =>
4453+
new Bun.CryptoHasher("sha256").update(JSON.stringify(messages)).digest("hex");
44094454
let previous: unknown[] = [];
44104455
for (let index = 0; index < 3; index++) {
44114456
const input = makeMessages(sessionId);
44124457
const output = { messages: [...input] as unknown[] };
44134458
await transform.run(sessionId, input, output, makeMeta(db, sessionId));
44144459
expect(transform.getState(sessionId).consecutiveFailures).toBe(0);
44154460
expect(output.messages).toHaveLength(native.length + 1);
4416-
if (previous.length > 0) expect(hash(output.messages.slice(0, previous.length))).toBe(hash(previous));
4417-
expect((output.messages as MessageLike[]).filter((msg) => msg.info.id === "settle")).toHaveLength(1);
4461+
if (previous.length > 0)
4462+
expect(hash(output.messages.slice(0, previous.length))).toBe(hash(previous));
4463+
expect(
4464+
(output.messages as MessageLike[]).filter((msg) => msg.info.id === "settle"),
4465+
).toHaveLength(1);
44184466
previous = structuredClone(output.messages);
44194467
}
44204468
});
@@ -4431,7 +4479,10 @@ describe("native output delta", () => {
44314479
const request = body as Record<string, unknown>;
44324480
transformBodies.push(request);
44334481
if (transformBodies.length === 1) {
4434-
return { decision: "SOFT+", native_messages: structuredClone(request.native_messages) };
4482+
return {
4483+
decision: "SOFT+",
4484+
native_messages: structuredClone(request.native_messages),
4485+
};
44354486
}
44364487
if (request.tail_delta) return { status: "ok", served_from: "transform" };
44374488
return { decision: "SOFT+", native_messages: structuredClone(healedNative) };
@@ -4552,7 +4603,10 @@ describe("delta prefix-mutation guard", () => {
45524603
} else {
45534604
moduleNativeSnapshot = structuredClone(suffix);
45544605
}
4555-
return { decision: "SOFT+", native_messages: structuredClone(moduleNativeSnapshot) };
4606+
return {
4607+
decision: "SOFT+",
4608+
native_messages: structuredClone(moduleNativeSnapshot),
4609+
};
45564610
},
45574611
};
45584612
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });
@@ -4641,7 +4695,9 @@ describe("delta prefix-mutation guard", () => {
46414695
const moduleClient: RustModeModuleClient = {
46424696
call: async ({ method, body }) => {
46434697
if (method === "transform") requestBodies.push(body as Record<string, unknown>);
4644-
return method === "transform" ? { decision: "SOFT+", native_messages: [] } : { ok: true };
4698+
return method === "transform"
4699+
? { decision: "SOFT+", native_messages: [] }
4700+
: { ok: true };
46454701
},
46464702
};
46474703
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });
@@ -4818,12 +4874,15 @@ describe("delta prefix-mutation guard", () => {
48184874
if (transformCalls === 2 || transformCalls === 3) {
48194875
throw new Error("CK message block identity drift");
48204876
}
4821-
return { decision: "SOFT+", native_messages: [
4822-
{
4823-
info: { id: "m1", role: "user", sessionID: sessionId },
4824-
parts: [{ type: "text", text: "module recovered" }],
4825-
},
4826-
] };
4877+
return {
4878+
decision: "SOFT+",
4879+
native_messages: [
4880+
{
4881+
info: { id: "m1", role: "user", sessionID: sessionId },
4882+
parts: [{ type: "text", text: "module recovered" }],
4883+
},
4884+
],
4885+
};
48274886
},
48284887
};
48294888
const transform = createRustModeTransform(makeDeps(db, moduleClient), { moduleClient });

‎packages/plugin/src/hooks/magic-context/rust-mode-transform.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,10 +2905,9 @@ export function createRustModeTransform(
29052905
: undefined;
29062906
const deferredFrozenPrefixDivergence =
29072907
!cacheBustingPass &&
2908-
[
2909-
deferredFirstDivergence?.block_id_old,
2910-
deferredFirstDivergence?.block_id_new,
2911-
].some((blockId) => blockId === "mc_m0#0" || blockId === "mc_m1#0");
2908+
[deferredFirstDivergence?.block_id_old, deferredFirstDivergence?.block_id_new].some(
2909+
(blockId) => blockId === "mc_m0#0" || blockId === "mc_m1#0",
2910+
);
29122911
if (deferredFrozenPrefixDivergence) {
29132912
// The module keeps the fingerprint from its last served response until an
29142913
// explicit cache invalidation. Freeze the host representation as well, so losing

0 commit comments

Comments
 (0)