create-expo-updates-server 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/template/.env.docker.example +1 -0
- package/dist/template/.env.example +2 -0
- package/dist/template/README.md +4 -1
- package/dist/template/app/api/admin/distribution-control/route.test.ts +153 -0
- package/dist/template/app/api/admin/distribution-control/route.ts +111 -0
- package/dist/template/app/api/admin/guard-actions/[id]/route.test.ts +60 -0
- package/dist/template/app/api/admin/guard-actions/[id]/route.ts +32 -0
- package/dist/template/app/api/admin/guard-actions/route.test.ts +123 -0
- package/dist/template/app/api/admin/guard-actions/route.ts +66 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/deactivate/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.test.ts +171 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/policy/route.ts +75 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/promote/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/rollback/route.ts +4 -1
- package/dist/template/app/api/admin/updates/[encodedKey]/route.ts +4 -1
- package/dist/template/app/updates/[encodedKey]/page.tsx +74 -6
- package/dist/template/app/updates/page.tsx +22 -1
- package/dist/template/docs/getting-started.md +1 -0
- package/dist/template/docs/getting-started.ru.md +2 -1
- package/dist/template/docs/migrations/2026-09-01-ota-update-policy.sql +108 -0
- package/dist/template/docs/migrations/2026-09-01-p1-guard-actions.sql +19 -0
- package/dist/template/docs/migrations/2026-09-01-p2-simplify-ota-guard-policy.sql +69 -0
- package/dist/template/docs/migrations/2026-09-01-policy-publication-correction.sql +44 -0
- package/dist/template/docs/migrations/2026-09-02-ota-distribution-control.sql +377 -0
- package/dist/template/docs/migrations/schema.sql +539 -2
- package/dist/template/docs/operations-guide.md +52 -1
- package/dist/template/docs/ota-emergency-recovery.md +22 -0
- package/dist/template/docs/ota-update-policy.md +89 -0
- package/dist/template/docs/supabase-setup.md +2 -1
- package/dist/template/package-lock.json +2 -2
- package/dist/template/package.json +1 -1
- package/dist/template/src/client/admin-api.ts +80 -1
- package/dist/template/src/client/admin-types.ts +50 -2
- package/dist/template/src/client/distribution-control.tsx +231 -0
- package/dist/template/src/client/guard-action-combobox.test.ts +26 -0
- package/dist/template/src/client/guard-action-combobox.tsx +267 -0
- package/dist/template/src/client/guard-action-options.test.ts +62 -0
- package/dist/template/src/client/guard-action-options.ts +70 -0
- package/dist/template/src/client/update-policy-editor.test.ts +36 -0
- package/dist/template/src/client/update-policy-editor.tsx +436 -0
- package/dist/template/src/server/controllers/assets.test.ts +87 -0
- package/dist/template/src/server/controllers/assets.ts +26 -0
- package/dist/template/src/server/controllers/manifest.test.ts +413 -2
- package/dist/template/src/server/controllers/manifest.ts +103 -38
- package/dist/template/src/server/lib/admin-distribution-guard.test.ts +61 -0
- package/dist/template/src/server/lib/admin-update-policy.test.ts +176 -0
- package/dist/template/src/server/lib/admin-updates.test.ts +72 -0
- package/dist/template/src/server/lib/admin-updates.ts +169 -24
- package/dist/template/src/server/lib/distribution-control-migration.test.ts +94 -0
- package/dist/template/src/server/lib/distribution-control.test.ts +181 -0
- package/dist/template/src/server/lib/distribution-control.ts +259 -0
- package/dist/template/src/server/lib/guard-actions-migration.test.ts +56 -0
- package/dist/template/src/server/lib/guard-actions.test.ts +142 -0
- package/dist/template/src/server/lib/guard-actions.ts +106 -0
- package/dist/template/src/server/lib/ota-policy-migrations.test.ts +64 -0
- package/dist/template/src/server/lib/simple-policy-migration.test.ts +97 -0
- package/dist/template/src/server/lib/supabase.js +95 -8
- package/dist/template/src/server/lib/supabase.test.ts +194 -0
- package/dist/template/src/server/lib/update-policy.test.ts +98 -0
- package/dist/template/src/server/lib/update-policy.ts +171 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +10 -1
- package/dist/template/src/server/manifest/manifest-response.ts +0 -16
- package/dist/template/src/server/manifest/manifest-values.test.ts +54 -0
- package/dist/template/src/server/manifest/manifest-values.ts +145 -0
- package/dist/template/tsconfig.json +4 -1
- package/dist/template-manifest.json +239 -59
- package/package.json +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
filterGuardActionOptions,
|
|
5
|
+
GuardActionOption,
|
|
6
|
+
normalizeCreatableGuardAction,
|
|
7
|
+
} from "./guard-action-options";
|
|
8
|
+
import {
|
|
9
|
+
KeyboardEvent,
|
|
10
|
+
useId,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
} from "react";
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
value: string;
|
|
17
|
+
options: GuardActionOption[];
|
|
18
|
+
selectionDisabled: boolean;
|
|
19
|
+
canMutateCatalog: boolean;
|
|
20
|
+
mutationError?: string;
|
|
21
|
+
onChange: (actionKey: string) => void;
|
|
22
|
+
onCreate: (actionKey: string) => Promise<void>;
|
|
23
|
+
onDelete: (option: GuardActionOption) => Promise<void>;
|
|
24
|
+
onRetry?: () => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default function GuardActionCombobox({
|
|
28
|
+
value,
|
|
29
|
+
options,
|
|
30
|
+
selectionDisabled,
|
|
31
|
+
canMutateCatalog,
|
|
32
|
+
mutationError,
|
|
33
|
+
onChange,
|
|
34
|
+
onCreate,
|
|
35
|
+
onDelete,
|
|
36
|
+
onRetry,
|
|
37
|
+
}: Props) {
|
|
38
|
+
const generatedId = useId();
|
|
39
|
+
const popupId = `${generatedId}-popup`;
|
|
40
|
+
const errorId = `${generatedId}-error`;
|
|
41
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
42
|
+
const [draftValue, setDraftValue] = useState<string | null>(null);
|
|
43
|
+
const [open, setOpen] = useState(false);
|
|
44
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
45
|
+
const [inputError, setInputError] = useState("");
|
|
46
|
+
const inputValue = draftValue ?? value;
|
|
47
|
+
const filteredOptions = selectionDisabled
|
|
48
|
+
? options
|
|
49
|
+
: filterGuardActionOptions(options, inputValue);
|
|
50
|
+
|
|
51
|
+
let creatableValue: string | null = null;
|
|
52
|
+
try {
|
|
53
|
+
creatableValue = normalizeCreatableGuardAction(inputValue);
|
|
54
|
+
} catch {
|
|
55
|
+
// Validation feedback is shown when the user attempts to create.
|
|
56
|
+
}
|
|
57
|
+
const exactOption = creatableValue
|
|
58
|
+
? options.find((option) => option.actionKey === creatableValue)
|
|
59
|
+
: undefined;
|
|
60
|
+
const showCreate =
|
|
61
|
+
!selectionDisabled && Boolean(creatableValue) && !exactOption;
|
|
62
|
+
const rowCount = filteredOptions.length + (showCreate ? 1 : 0);
|
|
63
|
+
|
|
64
|
+
const choose = (actionKey: string) => {
|
|
65
|
+
onChange(actionKey);
|
|
66
|
+
setDraftValue(null);
|
|
67
|
+
setInputError("");
|
|
68
|
+
setOpen(false);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const chooseOption = (option: GuardActionOption) => {
|
|
72
|
+
choose(option.actionKey);
|
|
73
|
+
if (!option.persisted) {
|
|
74
|
+
void onCreate(option.actionKey);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const create = async () => {
|
|
79
|
+
let actionKey: string;
|
|
80
|
+
try {
|
|
81
|
+
actionKey = normalizeCreatableGuardAction(inputValue);
|
|
82
|
+
} catch (error: unknown) {
|
|
83
|
+
setInputError((error as Error).message);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
choose(actionKey);
|
|
88
|
+
await onCreate(actionKey);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const activateRow = (index: number) => {
|
|
92
|
+
if (index < filteredOptions.length) {
|
|
93
|
+
chooseOption(filteredOptions[index]);
|
|
94
|
+
} else if (showCreate) {
|
|
95
|
+
void create();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
100
|
+
if (selectionDisabled) {
|
|
101
|
+
if (event.key === "Escape") setOpen(false);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
setOpen(true);
|
|
107
|
+
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
108
|
+
setActiveIndex((current) => {
|
|
109
|
+
if (rowCount === 0) return -1;
|
|
110
|
+
if (current < 0) return direction > 0 ? 0 : rowCount - 1;
|
|
111
|
+
return (current + direction + rowCount) % rowCount;
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (event.key === "Enter") {
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
if (open && activeIndex >= 0) {
|
|
118
|
+
activateRow(activeIndex);
|
|
119
|
+
} else if (exactOption) {
|
|
120
|
+
chooseOption(exactOption);
|
|
121
|
+
} else {
|
|
122
|
+
void create();
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (event.key === "Escape") {
|
|
127
|
+
setDraftValue(null);
|
|
128
|
+
setInputError("");
|
|
129
|
+
setOpen(false);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
ref={rootRef}
|
|
136
|
+
className="relative min-w-56 flex-1"
|
|
137
|
+
onBlur={(event) => {
|
|
138
|
+
if (!rootRef.current?.contains(event.relatedTarget)) {
|
|
139
|
+
setOpen(false);
|
|
140
|
+
setDraftValue(null);
|
|
141
|
+
}
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<input
|
|
145
|
+
value={inputValue}
|
|
146
|
+
maxLength={100}
|
|
147
|
+
readOnly={selectionDisabled}
|
|
148
|
+
aria-disabled={selectionDisabled}
|
|
149
|
+
role="combobox"
|
|
150
|
+
aria-label="Rule action"
|
|
151
|
+
aria-autocomplete="list"
|
|
152
|
+
aria-haspopup="dialog"
|
|
153
|
+
aria-expanded={open}
|
|
154
|
+
aria-controls={popupId}
|
|
155
|
+
aria-describedby={
|
|
156
|
+
inputError || mutationError ? errorId : undefined
|
|
157
|
+
}
|
|
158
|
+
onFocus={() => setOpen(true)}
|
|
159
|
+
onChange={(event) => {
|
|
160
|
+
setDraftValue(event.target.value);
|
|
161
|
+
setInputError("");
|
|
162
|
+
setOpen(true);
|
|
163
|
+
setActiveIndex(-1);
|
|
164
|
+
}}
|
|
165
|
+
onKeyDown={handleKeyDown}
|
|
166
|
+
className="w-full rounded border border-zinc-300 bg-transparent p-2 text-sm dark:border-zinc-700"
|
|
167
|
+
placeholder="Action (required)"
|
|
168
|
+
/>
|
|
169
|
+
{open ? (
|
|
170
|
+
<div
|
|
171
|
+
id={popupId}
|
|
172
|
+
role="dialog"
|
|
173
|
+
aria-label="Guard action catalog"
|
|
174
|
+
className="absolute z-20 mt-1 max-h-60 w-full overflow-auto rounded-md border border-zinc-300 bg-white p-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900"
|
|
175
|
+
>
|
|
176
|
+
{filteredOptions.map((option, index) => (
|
|
177
|
+
<div
|
|
178
|
+
key={`${option.id || "policy"}:${option.actionKey}`}
|
|
179
|
+
className={`flex items-center rounded ${
|
|
180
|
+
activeIndex === index
|
|
181
|
+
? "bg-blue-50 dark:bg-blue-950"
|
|
182
|
+
: ""
|
|
183
|
+
}`}
|
|
184
|
+
>
|
|
185
|
+
<button
|
|
186
|
+
type="button"
|
|
187
|
+
tabIndex={-1}
|
|
188
|
+
disabled={selectionDisabled}
|
|
189
|
+
aria-current={
|
|
190
|
+
option.actionKey === value ? "true" : undefined
|
|
191
|
+
}
|
|
192
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
193
|
+
onClick={() => chooseOption(option)}
|
|
194
|
+
className="min-w-0 flex-1 truncate px-3 py-2 text-left text-sm disabled:cursor-default"
|
|
195
|
+
title={option.actionKey}
|
|
196
|
+
>
|
|
197
|
+
{option.actionKey}
|
|
198
|
+
</button>
|
|
199
|
+
{option.persisted && canMutateCatalog ? (
|
|
200
|
+
<button
|
|
201
|
+
type="button"
|
|
202
|
+
aria-label={`Delete ${option.actionKey} from action catalog`}
|
|
203
|
+
title="Delete from catalog"
|
|
204
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
205
|
+
onClick={(event) => {
|
|
206
|
+
event.stopPropagation();
|
|
207
|
+
void onDelete(option);
|
|
208
|
+
}}
|
|
209
|
+
className="m-1 rounded p-2 text-red-600 hover:bg-red-50 dark:hover:bg-red-950"
|
|
210
|
+
>
|
|
211
|
+
<svg
|
|
212
|
+
viewBox="0 0 24 24"
|
|
213
|
+
width="16"
|
|
214
|
+
height="16"
|
|
215
|
+
fill="none"
|
|
216
|
+
stroke="currentColor"
|
|
217
|
+
strokeWidth="2"
|
|
218
|
+
aria-hidden="true"
|
|
219
|
+
>
|
|
220
|
+
<path d="M3 6h18M8 6V4h8v2m-9 0 1 14h8l1-14M10 10v6m4-6v6" />
|
|
221
|
+
</svg>
|
|
222
|
+
</button>
|
|
223
|
+
) : null}
|
|
224
|
+
</div>
|
|
225
|
+
))}
|
|
226
|
+
{showCreate ? (
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
230
|
+
onClick={() => void create()}
|
|
231
|
+
className={`w-full rounded px-3 py-2 text-left text-sm font-medium text-blue-700 dark:text-blue-300 ${
|
|
232
|
+
activeIndex === filteredOptions.length
|
|
233
|
+
? "bg-blue-50 dark:bg-blue-950"
|
|
234
|
+
: ""
|
|
235
|
+
}`}
|
|
236
|
+
>
|
|
237
|
+
Create “{creatableValue}”
|
|
238
|
+
</button>
|
|
239
|
+
) : null}
|
|
240
|
+
{filteredOptions.length === 0 && !showCreate ? (
|
|
241
|
+
<p className="px-3 py-2 text-sm text-zinc-500">
|
|
242
|
+
No matching actions
|
|
243
|
+
</p>
|
|
244
|
+
) : null}
|
|
245
|
+
</div>
|
|
246
|
+
) : null}
|
|
247
|
+
{inputError || mutationError ? (
|
|
248
|
+
<div
|
|
249
|
+
id={errorId}
|
|
250
|
+
role="status"
|
|
251
|
+
className="mt-1 flex items-center gap-2 text-xs text-amber-700 dark:text-amber-300"
|
|
252
|
+
>
|
|
253
|
+
<span>{inputError || mutationError}</span>
|
|
254
|
+
{mutationError && onRetry ? (
|
|
255
|
+
<button
|
|
256
|
+
type="button"
|
|
257
|
+
onClick={() => void onRetry()}
|
|
258
|
+
className="underline"
|
|
259
|
+
>
|
|
260
|
+
Retry
|
|
261
|
+
</button>
|
|
262
|
+
) : null}
|
|
263
|
+
</div>
|
|
264
|
+
) : null}
|
|
265
|
+
</div>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
beginCatalogAttempt,
|
|
4
|
+
filterGuardActionOptions,
|
|
5
|
+
isCurrentCatalogAttempt,
|
|
6
|
+
mergeGuardActionOptions,
|
|
7
|
+
normalizeCreatableGuardAction,
|
|
8
|
+
} from "./guard-action-options";
|
|
9
|
+
|
|
10
|
+
const catalog = [
|
|
11
|
+
{
|
|
12
|
+
id: "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb",
|
|
13
|
+
actionKey: "zeta",
|
|
14
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa",
|
|
18
|
+
actionKey: "alpha",
|
|
19
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
describe("guard action combobox helpers", () => {
|
|
24
|
+
it("sorts persisted options and filters case-insensitively", () => {
|
|
25
|
+
const options = mergeGuardActionOptions(catalog, []);
|
|
26
|
+
expect(options.map((option) => option.actionKey)).toEqual([
|
|
27
|
+
"alpha",
|
|
28
|
+
"zeta",
|
|
29
|
+
]);
|
|
30
|
+
expect(filterGuardActionOptions(options, "ET")).toEqual([options[1]]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("merges exact out-of-catalog policy values without rewriting", () => {
|
|
34
|
+
const options = mergeGuardActionOptions(catalog, [
|
|
35
|
+
"Alpha",
|
|
36
|
+
"alpha",
|
|
37
|
+
"legacy-action",
|
|
38
|
+
]);
|
|
39
|
+
expect(options.slice(2)).toEqual([
|
|
40
|
+
{ id: null, actionKey: "Alpha", persisted: false },
|
|
41
|
+
{ id: null, actionKey: "legacy-action", persisted: false },
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("normalizes only newly created values and validates catalog limits", () => {
|
|
46
|
+
expect(normalizeCreatableGuardAction(" new-action ")).toBe("new-action");
|
|
47
|
+
expect(() => normalizeCreatableGuardAction("bad\tvalue")).toThrow(
|
|
48
|
+
/control characters/,
|
|
49
|
+
);
|
|
50
|
+
expect(() => normalizeCreatableGuardAction("x".repeat(101))).toThrow(
|
|
51
|
+
/between 1 and 100/,
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("invalidates a stale selected-action catalog attempt", () => {
|
|
56
|
+
const state = { current: 0 };
|
|
57
|
+
const staleAttempt = beginCatalogAttempt(state);
|
|
58
|
+
expect(isCurrentCatalogAttempt(state, staleAttempt)).toBe(true);
|
|
59
|
+
beginCatalogAttempt(state);
|
|
60
|
+
expect(isCurrentCatalogAttempt(state, staleAttempt)).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { GuardActionItem } from "./admin-types";
|
|
2
|
+
|
|
3
|
+
export type GuardActionOption = {
|
|
4
|
+
id: string | null;
|
|
5
|
+
actionKey: string;
|
|
6
|
+
persisted: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type CatalogAttempt = { current: number };
|
|
10
|
+
|
|
11
|
+
const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f-\u009f]/;
|
|
12
|
+
|
|
13
|
+
export function normalizeCreatableGuardAction(input: string): string {
|
|
14
|
+
const actionKey = input.trim();
|
|
15
|
+
if (actionKey.length < 1 || actionKey.length > 100) {
|
|
16
|
+
throw new Error("Action must contain between 1 and 100 characters.");
|
|
17
|
+
}
|
|
18
|
+
if (CONTROL_CHARACTER_PATTERN.test(actionKey)) {
|
|
19
|
+
throw new Error("Action must not contain control characters.");
|
|
20
|
+
}
|
|
21
|
+
return actionKey;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function mergeGuardActionOptions(
|
|
25
|
+
catalog: GuardActionItem[],
|
|
26
|
+
currentPolicyValues: string[],
|
|
27
|
+
): GuardActionOption[] {
|
|
28
|
+
const options: GuardActionOption[] = catalog
|
|
29
|
+
.map((item) => ({
|
|
30
|
+
id: item.id,
|
|
31
|
+
actionKey: item.actionKey,
|
|
32
|
+
persisted: true,
|
|
33
|
+
}))
|
|
34
|
+
.sort((left, right) =>
|
|
35
|
+
left.actionKey.localeCompare(right.actionKey, "en"),
|
|
36
|
+
);
|
|
37
|
+
const exactValues = new Set(options.map((option) => option.actionKey));
|
|
38
|
+
|
|
39
|
+
for (const actionKey of currentPolicyValues) {
|
|
40
|
+
if (actionKey.length === 0 || exactValues.has(actionKey)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
exactValues.add(actionKey);
|
|
44
|
+
options.push({ id: null, actionKey, persisted: false });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return options;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function filterGuardActionOptions(
|
|
51
|
+
options: GuardActionOption[],
|
|
52
|
+
query: string,
|
|
53
|
+
): GuardActionOption[] {
|
|
54
|
+
const normalizedQuery = query.toLocaleLowerCase();
|
|
55
|
+
return options.filter((option) =>
|
|
56
|
+
option.actionKey.toLocaleLowerCase().includes(normalizedQuery),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function beginCatalogAttempt(attempt: CatalogAttempt): number {
|
|
61
|
+
attempt.current += 1;
|
|
62
|
+
return attempt.current;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isCurrentCatalogAttempt(
|
|
66
|
+
state: CatalogAttempt,
|
|
67
|
+
attempt: number,
|
|
68
|
+
): boolean {
|
|
69
|
+
return state.current === attempt;
|
|
70
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
const source = readFileSync(
|
|
5
|
+
new URL("./update-policy-editor.tsx", import.meta.url),
|
|
6
|
+
"utf8",
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
describe("simple update policy editor", () => {
|
|
10
|
+
it("contains only the unconditional Guard editor model", () => {
|
|
11
|
+
expect(source).toContain("Guard enabled");
|
|
12
|
+
expect(source).toContain("applies unconditionally");
|
|
13
|
+
expect(source).toContain("Optional custom JSON payload");
|
|
14
|
+
expect(source).not.toMatch(
|
|
15
|
+
/Priority|OR group|AND condition|UpdatePolicyRule|conditions/,
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("keeps catalog-only creation independent from policy editing", () => {
|
|
20
|
+
expect(source).toContain("canWriteGuardActions ? (");
|
|
21
|
+
expect(source).toContain("Add action to catalog");
|
|
22
|
+
expect(source).toContain(
|
|
23
|
+
"Adds a reusable catalog item without changing this policy.",
|
|
24
|
+
);
|
|
25
|
+
expect(source).toContain("Guard action catalog entries");
|
|
26
|
+
expect(source).toContain("canWriteGuardActions ? (");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("retries only the currently selected action", () => {
|
|
30
|
+
expect(source).toContain(
|
|
31
|
+
'persistSelectedAction(policy.guard?.action || "")',
|
|
32
|
+
);
|
|
33
|
+
expect(source).toContain("beginCatalogAttempt(actionAttempt.current)");
|
|
34
|
+
expect(source).toContain("setActionError(\"\")");
|
|
35
|
+
});
|
|
36
|
+
});
|