refactor(schema): apply session review decisions (#35793)
This commit is contained in:
parent
d27746e5b3
commit
ed6ad272ec
142 changed files with 4239 additions and 3174 deletions
|
|
@ -10,10 +10,30 @@ import { Pty } from "../src/pty.js"
|
|||
import { Question } from "../src/question.js"
|
||||
import { Session } from "../src/session.js"
|
||||
import { SessionMessage } from "../src/session-message.js"
|
||||
import { SessionInput } from "../src/session-input.js"
|
||||
import { FileDiff } from "../src/file-diff.js"
|
||||
import { Money } from "../src/money.js"
|
||||
import { Skill } from "../src/skill.js"
|
||||
import { Shell } from "../src/shell.js"
|
||||
import { PersistedRevert } from "../src/session-revert.js"
|
||||
import { SessionTodo } from "../src/session-todo.js"
|
||||
import { optional } from "../src/schema.js"
|
||||
|
||||
describe("contract hygiene", () => {
|
||||
test("keeps absolute costs distinct from model rates", () => {
|
||||
const usd = Money.USD.make(1)
|
||||
const rate = Money.USDPerMillionTokens.make(1)
|
||||
// @ts-expect-error Model rates are not absolute costs.
|
||||
const invalidUSD: Money.USD = rate
|
||||
// @ts-expect-error Absolute costs are not model rates.
|
||||
const invalidRate: Money.USDPerMillionTokens = usd
|
||||
|
||||
expect(invalidUSD).toBe(Money.USD.make(1))
|
||||
expect(invalidRate).toBe(Money.USDPerMillionTokens.make(1))
|
||||
expect(Money.USD.zero).toBe(Money.USD.make(0))
|
||||
expect(Money.USDPerMillionTokens.zero).toBe(Money.USDPerMillionTokens.make(0))
|
||||
})
|
||||
|
||||
test("optional properties preserve transformations and omit undefined while encoding", () => {
|
||||
const Value = Schema.Struct({ value: optional(Schema.FiniteFromString) })
|
||||
expect(Schema.decodeUnknownSync(Value)({ value: "1" })).toEqual({ value: 1 })
|
||||
|
|
@ -71,6 +91,7 @@ describe("contract hygiene", () => {
|
|||
Project.Info,
|
||||
Pty.Info,
|
||||
Session.ListAnchor,
|
||||
Session.Revert,
|
||||
].map((schema) => schema.ast.annotations?.identifier)
|
||||
|
||||
expect(identifiers.every((identifier) => typeof identifier === "string")).toBe(true)
|
||||
|
|
@ -104,9 +125,76 @@ describe("contract hygiene", () => {
|
|||
name: "search",
|
||||
executed: true,
|
||||
providerState: { itemId: "item_1" },
|
||||
state: { status: "pending", input: "" },
|
||||
state: { status: "streaming", input: "" },
|
||||
time: { created: DateTime.makeUnsafe(0) },
|
||||
}),
|
||||
).not.toHaveProperty("provider")
|
||||
})
|
||||
|
||||
test("reviewed session contracts use their canonical current shapes", () => {
|
||||
expect(SessionMessage.Info.ast.annotations?.identifier).toBe("Session.Message.Info")
|
||||
expect(SessionInput.Info.ast.annotations?.identifier).toBe("SessionInput.Info")
|
||||
expect(Money.USD).not.toBe(Money.USDPerMillionTokens)
|
||||
expect(
|
||||
FileDiff.Info.make({ file: "src/index.ts", patch: "@@", additions: 1, deletions: 0, status: "modified" }),
|
||||
).toEqual({ file: "src/index.ts", patch: "@@", additions: 1, deletions: 0, status: "modified" })
|
||||
expect(
|
||||
SessionMessage.Shell.make({
|
||||
id: SessionMessage.ID.make("msg_shell"),
|
||||
type: "shell",
|
||||
shellID: Shell.ID.make("sh_test"),
|
||||
command: "pwd",
|
||||
status: "exited",
|
||||
exit: 0,
|
||||
time: { created: DateTime.makeUnsafe(0) },
|
||||
}),
|
||||
).not.toHaveProperty("shell")
|
||||
expect(
|
||||
SessionMessage.Skill.make({
|
||||
id: SessionMessage.ID.make("msg_skill"),
|
||||
type: "skill",
|
||||
skill: Skill.ID.make("effect"),
|
||||
name: Skill.Name.make("Effect"),
|
||||
text: "Use Effect",
|
||||
time: { created: DateTime.makeUnsafe(0) },
|
||||
}),
|
||||
).toMatchObject({ skill: "effect", name: "Effect" })
|
||||
expect(
|
||||
SessionMessage.CompactionFailed.make({
|
||||
id: SessionMessage.ID.make("msg_compaction"),
|
||||
type: "compaction",
|
||||
status: "failed",
|
||||
reason: "manual",
|
||||
error: { type: "compaction.failed", message: "failed" },
|
||||
time: { created: DateTime.makeUnsafe(0) },
|
||||
}),
|
||||
).not.toHaveProperty("summary")
|
||||
})
|
||||
|
||||
test("keeps shared persisted revert compatibility", () => {
|
||||
expect(
|
||||
Schema.decodeUnknownSync(Session.Revert)({
|
||||
messageID: "msg_legacy",
|
||||
snapshot: "tree",
|
||||
diff: "legacy patch",
|
||||
}),
|
||||
).not.toHaveProperty("diff")
|
||||
|
||||
const revert = Schema.decodeUnknownSync(PersistedRevert)({
|
||||
messageID: "msg_legacy",
|
||||
snapshot: "tree",
|
||||
diff: "legacy patch",
|
||||
files: [{ path: "src/index.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" }],
|
||||
})
|
||||
expect(String(revert.messageID)).toBe("msg_legacy")
|
||||
expect(String(revert.snapshot)).toBe("tree")
|
||||
expect(revert.files).toEqual([
|
||||
{ file: "src/index.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" },
|
||||
])
|
||||
expect(Schema.encodeSync(PersistedRevert)(revert)).toEqual({
|
||||
messageID: "msg_legacy",
|
||||
snapshot: "tree",
|
||||
files: [{ file: "src/index.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" }],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -145,10 +145,17 @@ describe("public event manifest", () => {
|
|||
SessionEvent.Definitions.filter((definition) => definition.durability === "durable"),
|
||||
)
|
||||
expect(SessionEvent.UsageUpdated.durability).toBe("ephemeral")
|
||||
expect(SessionEvent.Compaction.Delta.durability).toBe("ephemeral")
|
||||
expect(EventManifest.Durable.has("session.compaction.delta.1")).toBe(false)
|
||||
expect(EventManifest.ServerDefinitions).toContain(SessionEvent.UsageUpdated)
|
||||
expect(EventManifest.Definitions.every((definition) => definition.durability !== undefined)).toBe(true)
|
||||
})
|
||||
|
||||
test("uses the current Session skill event as durable version 1", () => {
|
||||
expect(EventManifest.Durable.get("session.skill.activated.1")).toBe(SessionEvent.Skill.Activated)
|
||||
expect(EventManifest.Latest.get("session.skill.activated")).toBe(SessionEvent.Skill.Activated)
|
||||
})
|
||||
|
||||
test("keeps simplified session fragment and tool payloads on durable version 1", () => {
|
||||
const sessionID = SessionID.make("ses_test")
|
||||
const assistantMessageID = SessionMessage.ID.make("msg_test")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue