test(shared): remove unsafe test assertions
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -216,20 +216,23 @@ Body content`
|
||||
agent: string
|
||||
}
|
||||
|
||||
interface FrontmatterWithExtras extends MinimalMeta {
|
||||
extra_field: string
|
||||
another_extra: { nested: string; array: string[] }
|
||||
custom_boolean: boolean
|
||||
custom_number: number
|
||||
}
|
||||
|
||||
// when
|
||||
const result = parseFrontmatter<MinimalMeta>(content)
|
||||
const result = parseFrontmatter<FrontmatterWithExtras>(content)
|
||||
|
||||
// then
|
||||
expect(result.data.description).toBe("Test command")
|
||||
expect(result.data.agent).toBe("build")
|
||||
expect(result.body).toBe("Body content")
|
||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
||||
expect(result.data.extra_field).toBe("should not fail")
|
||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
||||
expect(result.data.another_extra).toEqual({ nested: "value", array: ["item1", "item2"] })
|
||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
||||
expect(result.data.custom_boolean).toBe(true)
|
||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
||||
expect(result.data.custom_number).toBe(42)
|
||||
})
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ describe("collectGitDiffStats", () => {
|
||||
expect(execSyncSpy).not.toHaveBeenCalled()
|
||||
expect(execFileSyncSpy.mock.calls.length).toBeGreaterThanOrEqual(3)
|
||||
|
||||
const calls = execFileSyncSpy.mock.calls as unknown as Array<[string, string[], { cwd?: string }]>
|
||||
const calls = testCoerce<Array<[string, string[], { cwd?: string }]>>(execFileSyncSpy.mock.calls)
|
||||
const diffCall = calls.find(([, args]) => args[0] === "diff")
|
||||
const statusCall = calls.find(([, args]) => args[0] === "status")
|
||||
const untrackedCall = calls.find(([, args]) => args[0] === "ls-files")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import * as fs from "node:fs"
|
||||
import * as path from "node:path"
|
||||
import { log } from "../logger"
|
||||
import { isRecord } from "../record-type-guard"
|
||||
import { writeFileAtomically } from "../write-file-atomically"
|
||||
|
||||
/**
|
||||
@@ -48,14 +49,9 @@ export function readAppliedMigrations(configPath: string): Set<string> {
|
||||
return new Set()
|
||||
}
|
||||
const content = fs.readFileSync(sidecarPath, "utf-8")
|
||||
const parsed = JSON.parse(content) as unknown
|
||||
if (
|
||||
parsed &&
|
||||
typeof parsed === "object" &&
|
||||
!Array.isArray(parsed) &&
|
||||
Array.isArray((parsed as MigrationsSidecar).appliedMigrations)
|
||||
) {
|
||||
return new Set((parsed as MigrationsSidecar).appliedMigrations.filter((m): m is string => typeof m === "string"))
|
||||
const parsed: unknown = JSON.parse(content)
|
||||
if (isRecord(parsed) && Array.isArray(parsed.appliedMigrations)) {
|
||||
return new Set(parsed.appliedMigrations.filter((migration): migration is string => typeof migration === "string"))
|
||||
}
|
||||
return new Set()
|
||||
} catch (err) {
|
||||
|
||||
@@ -217,7 +217,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
const client = { session: { promptAsync: promptMock } }
|
||||
|
||||
// when calling promptWithModelSuggestionRetry
|
||||
await promptWithModelSuggestionRetry(client as any, {
|
||||
await promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -244,7 +244,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
// when calling promptWithModelSuggestionRetry
|
||||
// then should throw the error without retrying
|
||||
await expect(
|
||||
promptWithModelSuggestionRetry(client as any, {
|
||||
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
agent: "explore",
|
||||
@@ -267,7 +267,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
// when calling promptWithModelSuggestionRetry
|
||||
// then should throw the original error
|
||||
await expect(
|
||||
promptWithModelSuggestionRetry(client as any, {
|
||||
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -288,7 +288,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
// when calling promptWithModelSuggestionRetry
|
||||
// then should throw the error
|
||||
await expect(
|
||||
promptWithModelSuggestionRetry(client as any, {
|
||||
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -307,7 +307,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
const client = { session: { promptAsync: promptMock } }
|
||||
|
||||
// when calling with additional body fields
|
||||
await promptWithModelSuggestionRetry(client as any, {
|
||||
await promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
agent: "explore",
|
||||
@@ -341,7 +341,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
// when calling promptWithModelSuggestionRetry
|
||||
// then should throw the error
|
||||
await expect(
|
||||
promptWithModelSuggestionRetry(client as any, {
|
||||
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -365,7 +365,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
||||
// when calling without model in body
|
||||
// then should throw the error
|
||||
await expect(
|
||||
promptWithModelSuggestionRetry(client as any, {
|
||||
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -386,7 +386,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
||||
const client = { session: { prompt: promptMock, promptAsync: promptAsyncMock } }
|
||||
|
||||
// when calling promptSyncWithModelSuggestionRetry
|
||||
await promptSyncWithModelSuggestionRetry(client as any, {
|
||||
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -424,7 +424,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
||||
// when calling with short timeout
|
||||
// then should abort the request and throw timeout error
|
||||
await expect(
|
||||
promptSyncWithModelSuggestionRetry(client as any, {
|
||||
promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -451,7 +451,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
||||
const client = { session: { prompt: promptMock } }
|
||||
|
||||
// when calling promptSyncWithModelSuggestionRetry
|
||||
await promptSyncWithModelSuggestionRetry(client as any, {
|
||||
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -477,7 +477,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
||||
// when calling promptSyncWithModelSuggestionRetry
|
||||
// then should throw the original error
|
||||
await expect(
|
||||
promptSyncWithModelSuggestionRetry(client as any, {
|
||||
promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -504,7 +504,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
||||
// when calling without model in body
|
||||
// then should throw (cannot retry without original model)
|
||||
await expect(
|
||||
promptSyncWithModelSuggestionRetry(client as any, {
|
||||
promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
parts: [{ type: "text", text: "hello" }],
|
||||
@@ -521,7 +521,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
||||
const client = { session: { prompt: promptMock } }
|
||||
|
||||
// when calling with additional body fields
|
||||
await promptSyncWithModelSuggestionRetry(client as any, {
|
||||
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||
path: { id: "session-1" },
|
||||
body: {
|
||||
agent: "multimodal-looker",
|
||||
|
||||
Reference in New Issue
Block a user