Repository navigation
Expand file tree
/
Copy pathtest-update-codex-plugins.sh
More file actions
executable file
·142 lines (131 loc) · 3.78 KB
/
Copy pathtest-update-codex-plugins.sh
File metadata and controls
executable file
·142 lines (131 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
updater="$repo_root/scripts/update-codex-plugins.sh"
temp_root="$(mktemp -d "${TMPDIR:-/tmp}/codex-plugin-update-test.XXXXXX")"
cleanup() {
find "$temp_root" -depth -delete
}
trap cleanup EXIT
fake_bin="$temp_root/bin"
log_file="$temp_root/codex.log"
mkdir -p "$fake_bin"
cat >"$fake_bin/codex" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
case "$*" in
"plugin list --json")
cat <<'JSON'
{
"installed": [
{
"pluginId": "installed-one@demo",
"name": "installed-one",
"marketplaceName": "demo",
"installed": true,
"enabled": true
},
{
"pluginId": "disabled-one@demo",
"name": "disabled-one",
"marketplaceName": "demo",
"installed": true,
"enabled": false
},
{
"pluginId": "local-one@local-market",
"name": "local-one",
"marketplaceName": "local-market",
"installed": true,
"enabled": true
}
],
"available": [
{
"pluginId": "not-installed@demo",
"name": "not-installed",
"marketplaceName": "demo",
"installed": false,
"enabled": false
}
]
}
JSON
;;
"plugin marketplace list --json")
cat <<'JSON'
{
"marketplaces": [
{
"name": "demo",
"marketplaceSource": {
"sourceType": "git",
"source": "https://example.invalid/demo.git"
}
},
{
"name": "empty-git",
"marketplaceSource": {
"sourceType": "git",
"source": "https://example.invalid/empty.git"
}
},
{
"name": "local-market",
"marketplaceSource": {
"sourceType": "local",
"source": "/tmp/local-market"
}
}
]
}
JSON
;;
"plugin marketplace upgrade demo --json")
printf 'upgrade demo\n' >>"$FAKE_CODEX_LOG"
printf '{"selectedMarketplaces":["demo"],"upgradedRoots":["/tmp/demo"],"errors":[]}\n'
;;
"plugin marketplace upgrade empty-git --json")
printf 'upgrade empty-git\n' >>"$FAKE_CODEX_LOG"
printf '{"selectedMarketplaces":["empty-git"],"upgradedRoots":["/tmp/empty-git"],"errors":[]}\n'
;;
"plugin add installed-one@demo --json")
printf 'add installed-one@demo\n' >>"$FAKE_CODEX_LOG"
printf '{"pluginId":"installed-one@demo"}\n'
;;
*)
printf 'Unexpected codex invocation: %s\n' "$*" >&2
exit 97
;;
esac
EOF
chmod +x "$fake_bin/codex"
PATH="$fake_bin:$PATH" FAKE_CODEX_LOG="$log_file" "$updater" >"$temp_root/output.txt" 2>"$temp_root/error.txt"
expected_log="$temp_root/expected.log"
cat >"$expected_log" <<'EOF'
upgrade demo
upgrade empty-git
add installed-one@demo
EOF
cmp "$expected_log" "$log_file"
grep -F "Skipping disabled installed plugin 'disabled-one@demo'" "$temp_root/error.txt" >/dev/null
grep -F "Skipping marketplace 'local-market': source type is 'local', not 'git'" "$temp_root/error.txt" >/dev/null
if grep -F 'not-installed@demo' "$log_file" >/dev/null; then
printf 'Updater attempted to install an uninstalled marketplace plugin\n' >&2
exit 1
fi
: >"$log_file"
PATH="$fake_bin:$PATH" FAKE_CODEX_LOG="$log_file" "$updater" --dry-run --marketplace demo \
>"$temp_root/dry-run.txt" 2>"$temp_root/dry-run-error.txt"
test ! -s "$log_file"
grep -F 'Would run: codex plugin marketplace upgrade demo --json' "$temp_root/dry-run.txt" >/dev/null
grep -F 'Would run: codex plugin add installed-one@demo --json' "$temp_root/dry-run.txt" >/dev/null
: >"$log_file"
PATH="$fake_bin:$PATH" FAKE_CODEX_LOG="$log_file" "$updater" --marketplace empty-git \
>"$temp_root/empty.txt" 2>"$temp_root/empty-error.txt"
grep -Fx 'upgrade empty-git' "$log_file" >/dev/null
if grep -F 'add ' "$log_file" >/dev/null; then
printf 'Updater installed a plugin from an empty marketplace\n' >&2
exit 1
fi
printf 'Codex Plugin updater test passed.\n'