Skip to content

Commit 5b74dff

Browse files
committed
test: remove sqlite3 cli dependency from wrapper tests
1 parent 387b131 commit 5b74dff

1 file changed

Lines changed: 59 additions & 18 deletions

File tree

test/opencode-memory.test.ts

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -809,14 +809,22 @@ exit 0
809809
const tmpDir = join(root, "tmp")
810810
const claudeDir = join(root, "claude")
811811
const stateFile = join(root, "delete-log")
812-
const dbPath = seedSessionDb(homeDir, [
812+
const futureBaseMs = Date.now() + 60_000
813+
seedSessionDb(homeDir, [
813814
{
814815
id: "ses_wrapped_target",
815816
title: "Wrapped Main Task",
816817
directory: root,
817818
timeCreated: 1,
818819
timeUpdated: 1,
819820
},
821+
{
822+
id: "ses_fork_cleanup_target",
823+
title: "Wrapped Main Task (fork #1)",
824+
directory: root,
825+
timeCreated: futureBaseMs,
826+
timeUpdated: futureBaseMs,
827+
},
820828
])
821829

822830
mkdirSync(fakeBin, { recursive: true })
@@ -829,7 +837,6 @@ exit 0
829837
`#!/usr/bin/env bash
830838
set -euo pipefail
831839
DELETE_LOG="${stateFile}"
832-
DB_PATH="${dbPath}"
833840
if [ "\${1:-}" = "session" ] && [ "\${2:-}" = "list" ]; then
834841
echo '[{"id":"ses_wrapped_target","updated":20,"created":20,"directory":"${root}","title":"Wrapped Main Task"}]'
835842
exit 0
@@ -857,8 +864,6 @@ if [ "\${1:-}" = "run" ] && [ "\${2:-}" != "-s" ]; then
857864
exit 0
858865
fi
859866
if [ "\${1:-}" = "run" ] && [ "\${2:-}" = "-s" ]; then
860-
now_ms=$(( $(date +%s) * 1000 ))
861-
sqlite3 "$DB_PATH" "INSERT OR REPLACE INTO session (id, parent_id, directory, title, time_created, time_updated) VALUES ('ses_fork_cleanup_target', NULL, '${root}', 'Wrapped Main Task (fork #1)', $now_ms, $now_ms);"
862867
mkdir -p "$CLAUDE_CONFIG_DIR/transcripts"
863868
printf '{"type":"user","content":"fork"}\n{"type":"tool_use","content":""}\n' > "$CLAUDE_CONFIG_DIR/transcripts/ses_fork_cleanup_target.jsonl"
864869
echo "forked cleanup run"
@@ -868,6 +873,13 @@ exit 0
868873
`,
869874
)
870875

876+
writeExecutable(
877+
join(fakeBin, "sqlite3"),
878+
`#!/usr/bin/env bash
879+
exit 127
880+
`,
881+
)
882+
871883
const result = spawnSync("bash", [scriptPath, "run", "hello"], {
872884
cwd: root,
873885
encoding: "utf-8",
@@ -884,6 +896,7 @@ exit 0
884896
})
885897

886898
expect(result.status).toBe(0)
899+
expect(existsSync(join(claudeDir, "transcripts", "ses_fork_cleanup_target.jsonl"))).toBe(true)
887900
expect(existsSync(stateFile)).toBe(true)
888901
expect(readFileSync(stateFile, "utf-8")).toContain("ses_fork_cleanup_target")
889902
})
@@ -896,14 +909,29 @@ exit 0
896909
const claudeDir = join(root, "claude")
897910
const deleteLog = join(root, "delete-log")
898911
const stateFile = join(root, "state")
899-
const dbPath = seedSessionDb(homeDir, [
912+
const futureBaseMs = Date.now() + 60_000
913+
seedSessionDb(homeDir, [
900914
{
901915
id: "ses_wrapped_target",
902916
title: "Wrapped Main Task",
903917
directory: root,
904918
timeCreated: 1,
905919
timeUpdated: 1,
906920
},
921+
{
922+
id: "ses_fork_cleanup_target",
923+
title: "Wrapped Main Task (fork #1)",
924+
directory: root,
925+
timeCreated: futureBaseMs,
926+
timeUpdated: futureBaseMs,
927+
},
928+
{
929+
id: "ses_parallel_real",
930+
title: "Parallel normal session",
931+
directory: root,
932+
timeCreated: futureBaseMs + 1000,
933+
timeUpdated: futureBaseMs + 1000,
934+
},
907935
])
908936

909937
mkdirSync(fakeBin, { recursive: true })
@@ -917,7 +945,6 @@ exit 0
917945
set -euo pipefail
918946
DELETE_LOG="${deleteLog}"
919947
STATE_FILE="${stateFile}"
920-
DB_PATH="${dbPath}"
921948
if [ "\${1:-}" = "session" ] && [ "\${2:-}" = "list" ]; then
922949
if [ ! -f "$STATE_FILE" ]; then
923950
echo '[{"id":"ses_existing_old","updated":1,"created":1,"directory":"${root}","title":"Existing Session"}]'
@@ -944,9 +971,6 @@ if [ "\${1:-}" != "session" ] && ! { [ "\${1:-}" = "run" ] && [ "\${2:-}" = "-s"
944971
exit 0
945972
fi
946973
if [ "\${1:-}" = "run" ] && [ "\${2:-}" = "-s" ]; then
947-
now_ms=$(( $(date +%s) * 1000 ))
948-
sqlite3 "$DB_PATH" "INSERT OR REPLACE INTO session (id, parent_id, directory, title, time_created, time_updated) VALUES ('ses_fork_cleanup_target', NULL, '${root}', 'Wrapped Main Task (fork #1)', $now_ms, $now_ms);"
949-
sqlite3 "$DB_PATH" "INSERT OR REPLACE INTO session (id, parent_id, directory, title, time_created, time_updated) VALUES ('ses_parallel_real', NULL, '${root}', 'Parallel normal session', $((now_ms + 1000)), $((now_ms + 1000)));"
950974
mkdir -p "$CLAUDE_CONFIG_DIR/transcripts"
951975
printf '{"type":"user","content":"fork"}\n{"type":"tool_use","content":""}\n' > "$CLAUDE_CONFIG_DIR/transcripts/ses_fork_cleanup_target.jsonl"
952976
sleep 1
@@ -988,14 +1012,29 @@ exit 0
9881012
const tmpDir = join(root, "tmp")
9891013
const claudeDir = join(root, "claude")
9901014
const deleteLog = join(root, "delete-log")
991-
const dbPath = seedSessionDb(homeDir, [
1015+
const futureBaseMs = Date.now() + 60_000
1016+
seedSessionDb(homeDir, [
9921017
{
9931018
id: "ses_wrapped_target",
9941019
title: "Wrapped Main Task",
9951020
directory: root,
9961021
timeCreated: 1,
9971022
timeUpdated: 1,
9981023
},
1024+
{
1025+
id: "ses_fork_cleanup_one",
1026+
title: "Wrapped Main Task (fork #1)",
1027+
directory: root,
1028+
timeCreated: futureBaseMs,
1029+
timeUpdated: futureBaseMs,
1030+
},
1031+
{
1032+
id: "ses_fork_cleanup_two",
1033+
title: "Wrapped Main Task (fork #2)",
1034+
directory: root,
1035+
timeCreated: futureBaseMs + 1000,
1036+
timeUpdated: futureBaseMs + 1000,
1037+
},
9991038
])
10001039

10011040
mkdirSync(fakeBin, { recursive: true })
@@ -1008,7 +1047,6 @@ exit 0
10081047
`#!/usr/bin/env bash
10091048
set -euo pipefail
10101049
DELETE_LOG="${deleteLog}"
1011-
DB_PATH="${dbPath}"
10121050
if [ "\${1:-}" = "session" ] && [ "\${2:-}" = "list" ]; then
10131051
echo '[{"id":"ses_wrapped_target","updated":20,"created":20,"directory":"${root}","title":"Wrapped Main Task"}]'
10141052
exit 0
@@ -1030,9 +1068,6 @@ if [ "\${1:-}" = "run" ] && [ "\${2:-}" != "-s" ]; then
10301068
exit 0
10311069
fi
10321070
if [ "\${1:-}" = "run" ] && [ "\${2:-}" = "-s" ]; then
1033-
now_ms=$(( $(date +%s) * 1000 ))
1034-
sqlite3 "$DB_PATH" "INSERT OR REPLACE INTO session (id, parent_id, directory, title, time_created, time_updated) VALUES ('ses_fork_cleanup_one', NULL, '${root}', 'Wrapped Main Task (fork #1)', $now_ms, $now_ms);"
1035-
sqlite3 "$DB_PATH" "INSERT OR REPLACE INTO session (id, parent_id, directory, title, time_created, time_updated) VALUES ('ses_fork_cleanup_two', NULL, '${root}', 'Wrapped Main Task (fork #2)', $((now_ms + 1000)), $((now_ms + 1000)));"
10361071
mkdir -p "$CLAUDE_CONFIG_DIR/transcripts"
10371072
printf '{"type":"user","content":"fork-one"}\n{"type":"tool_use","content":""}\n' > "$CLAUDE_CONFIG_DIR/transcripts/ses_fork_cleanup_one.jsonl"
10381073
sleep 1
@@ -1070,7 +1105,16 @@ exit 0
10701105
const tmpDir = join(root, "tmp")
10711106
const claudeDir = join(root, "claude")
10721107
const deleteLog = join(root, "delete-log")
1073-
const dbPath = seedSessionDb(homeDir, [])
1108+
const futureBaseMs = Date.now() + 60_000
1109+
seedSessionDb(homeDir, [
1110+
{
1111+
id: "ses_fork_cleanup_target",
1112+
title: "Wrapped Main Task (fork #1)",
1113+
directory: root,
1114+
timeCreated: futureBaseMs,
1115+
timeUpdated: futureBaseMs,
1116+
},
1117+
])
10741118

10751119
mkdirSync(fakeBin, { recursive: true })
10761120
mkdirSync(homeDir, { recursive: true })
@@ -1082,7 +1126,6 @@ exit 0
10821126
`#!/usr/bin/env bash
10831127
set -euo pipefail
10841128
DELETE_LOG="${deleteLog}"
1085-
DB_PATH="${dbPath}"
10861129
if [ "\${1:-}" = "session" ] && [ "\${2:-}" = "list" ]; then
10871130
echo '[{"id":"ses_wrapped_target","updated":20,"created":20,"directory":"${root}","title":"Wrapped Main Task"}]'
10881131
exit 0
@@ -1104,8 +1147,6 @@ if [ "\${1:-}" = "run" ] && [ "\${2:-}" != "-s" ]; then
11041147
exit 0
11051148
fi
11061149
if [ "\${1:-}" = "run" ] && [ "\${2:-}" = "-s" ]; then
1107-
now_ms=$(( $(date +%s) * 1000 ))
1108-
sqlite3 "$DB_PATH" "INSERT OR REPLACE INTO session (id, parent_id, directory, title, time_created, time_updated) VALUES ('ses_fork_cleanup_target', NULL, '${root}', 'Wrapped Main Task (fork #1)', $now_ms, $now_ms);"
11091150
mkdir -p "$CLAUDE_CONFIG_DIR/transcripts"
11101151
printf '{"type":"user","content":"fork"}\n{"type":"tool_use","content":""}\n' > "$CLAUDE_CONFIG_DIR/transcripts/ses_fork_cleanup_target.jsonl"
11111152
echo "forked cleanup run"

0 commit comments

Comments
 (0)