Simplify compaction test helpers (#26742)
This commit is contained in:
@@ -226,12 +226,6 @@ async function summaryAssistant(sessionID: SessionID, parentID: MessageID, root:
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
async function lastCompactionPart(sessionID: SessionID) {
|
|
||||||
return (await svc.messages({ sessionID }))
|
|
||||||
.at(-2)
|
|
||||||
?.parts.find((item): item is MessageV2.CompactionPart => item.type === "compaction")
|
|
||||||
}
|
|
||||||
|
|
||||||
function createCompactionMarker(sessionID: SessionID) {
|
function createCompactionMarker(sessionID: SessionID) {
|
||||||
return SessionNs.Service.use((ssn) =>
|
return SessionNs.Service.use((ssn) =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
@@ -258,14 +252,6 @@ async function createCompactionMarkerAsync(sessionID: SessionID) {
|
|||||||
return run(createCompactionMarker(sessionID))
|
return run(createCompactionMarker(sessionID))
|
||||||
}
|
}
|
||||||
|
|
||||||
function readLastCompactionPart(sessionID: SessionID) {
|
|
||||||
return SessionNs.Service.use((ssn) => ssn.messages({ sessionID })).pipe(
|
|
||||||
Effect.map((messages) =>
|
|
||||||
messages.at(-2)?.parts.find((item): item is MessageV2.CompactionPart => item.type === "compaction"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function fake(
|
function fake(
|
||||||
input: Parameters<SessionProcessorModule.SessionProcessor.Interface["create"]>[0],
|
input: Parameters<SessionProcessorModule.SessionProcessor.Interface["create"]>[0],
|
||||||
result: "continue" | "compact",
|
result: "continue" | "compact",
|
||||||
@@ -379,6 +365,10 @@ function readCompactionPart(sessionID: SessionID) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function lastCompactionPart(sessionID: SessionID) {
|
||||||
|
return run(readCompactionPart(sessionID))
|
||||||
|
}
|
||||||
|
|
||||||
function llm() {
|
function llm() {
|
||||||
const queue: Array<
|
const queue: Array<
|
||||||
Stream.Stream<LLM.Event, unknown> | ((input: LLM.StreamInput) => Stream.Stream<LLM.Event, unknown>)
|
Stream.Stream<LLM.Event, unknown> | ((input: LLM.StreamInput) => Stream.Stream<LLM.Event, unknown>)
|
||||||
@@ -1057,7 +1047,7 @@ describe("session.compaction.process", () => {
|
|||||||
yield* createUserMessage(session.id, "first")
|
yield* createUserMessage(session.id, "first")
|
||||||
const keep = yield* createUserMessage(session.id, "second")
|
const keep = yield* createUserMessage(session.id, "second")
|
||||||
yield* createUserMessage(session.id, "third")
|
yield* createUserMessage(session.id, "third")
|
||||||
yield* SessionCompaction.use.create({ sessionID: session.id, agent: "build", model: ref, auto: false })
|
yield* createSummaryCompaction(session.id)
|
||||||
|
|
||||||
const msgs = yield* ssn.messages({ sessionID: session.id })
|
const msgs = yield* ssn.messages({ sessionID: session.id })
|
||||||
const parent = msgs.at(-1)?.info.id
|
const parent = msgs.at(-1)?.info.id
|
||||||
@@ -1069,7 +1059,7 @@ describe("session.compaction.process", () => {
|
|||||||
auto: false,
|
auto: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
const part = yield* readLastCompactionPart(session.id)
|
const part = yield* readCompactionPart(session.id)
|
||||||
expect(part?.type).toBe("compaction")
|
expect(part?.type).toBe("compaction")
|
||||||
expect(part?.tail_start_id).toBe(keep.id)
|
expect(part?.tail_start_id).toBe(keep.id)
|
||||||
}).pipe(Effect.provide(compactionProcessLayer({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) }))),
|
}).pipe(Effect.provide(compactionProcessLayer({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 10_000 }) }))),
|
||||||
@@ -1083,7 +1073,7 @@ describe("session.compaction.process", () => {
|
|||||||
yield* createUserMessage(session.id, "first")
|
yield* createUserMessage(session.id, "first")
|
||||||
yield* createUserMessage(session.id, "x".repeat(2_000))
|
yield* createUserMessage(session.id, "x".repeat(2_000))
|
||||||
const keep = yield* createUserMessage(session.id, "tiny")
|
const keep = yield* createUserMessage(session.id, "tiny")
|
||||||
yield* SessionCompaction.use.create({ sessionID: session.id, agent: "build", model: ref, auto: false })
|
yield* createSummaryCompaction(session.id)
|
||||||
|
|
||||||
const msgs = yield* ssn.messages({ sessionID: session.id })
|
const msgs = yield* ssn.messages({ sessionID: session.id })
|
||||||
const parent = msgs.at(-1)?.info.id
|
const parent = msgs.at(-1)?.info.id
|
||||||
@@ -1095,7 +1085,7 @@ describe("session.compaction.process", () => {
|
|||||||
auto: false,
|
auto: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
const part = yield* readLastCompactionPart(session.id)
|
const part = yield* readCompactionPart(session.id)
|
||||||
expect(part?.type).toBe("compaction")
|
expect(part?.type).toBe("compaction")
|
||||||
expect(part?.tail_start_id).toBe(keep.id)
|
expect(part?.tail_start_id).toBe(keep.id)
|
||||||
}).pipe(Effect.provide(compactionProcessLayer({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 100 }) }))),
|
}).pipe(Effect.provide(compactionProcessLayer({ config: cfg({ tail_turns: 2, preserve_recent_tokens: 100 }) }))),
|
||||||
|
|||||||
Reference in New Issue
Block a user