-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathenvironment-artifact.test.ts
More file actions
121 lines (105 loc) · 4.26 KB
/
Copy pathenvironment-artifact.test.ts
File metadata and controls
121 lines (105 loc) · 4.26 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
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect } from 'vitest';
import {
ENVIRONMENT_ARTIFACT_SCHEMA_VERSION,
EnvironmentArtifactSchema,
EnvironmentArtifactChecksumSchema,
EnvironmentArtifactFunctionSchema,
EnvironmentArtifactManifestSchema,
} from './environment-artifact.zod';
describe('EnvironmentArtifactSchema', () => {
const minimal = {
schemaVersion: ENVIRONMENT_ARTIFACT_SCHEMA_VERSION,
environmentId: 'proj_01HABCDE',
commitId: 'commit_01HABCDE',
checksum: { algorithm: 'sha256' as const, value: 'a1b2c3d4' },
metadata: {},
functions: [],
manifest: {},
};
it('accepts a minimal valid artifact', () => {
const parsed = EnvironmentArtifactSchema.parse(minimal);
expect(parsed.schemaVersion).toBe('0.1');
expect(parsed.functions).toEqual([]);
});
it('defaults functions to an empty array when omitted', () => {
const { functions: _omit, ...rest } = minimal;
const parsed = EnvironmentArtifactSchema.parse(rest);
expect(parsed.functions).toEqual([]);
});
it('rejects unknown schemaVersion values', () => {
const result = EnvironmentArtifactSchema.safeParse({ ...minimal, schemaVersion: '9.9' });
expect(result.success).toBe(false);
});
it('requires environmentId and commitId', () => {
expect(EnvironmentArtifactSchema.safeParse({ ...minimal, environmentId: '' }).success).toBe(false);
expect(EnvironmentArtifactSchema.safeParse({ ...minimal, commitId: '' }).success).toBe(false);
});
it('passes through unknown metadata categories without dropping them', () => {
const parsed = EnvironmentArtifactSchema.parse({
...minimal,
metadata: { objects: [{ name: 'account' }], futureCategory: [{ id: 'x' }] },
});
expect((parsed.metadata as Record<string, unknown>).futureCategory).toBeDefined();
});
it('accepts optional builtAt / builtWith provenance', () => {
const parsed = EnvironmentArtifactSchema.parse({
...minimal,
builtAt: '2026-04-26T00:00:00Z',
builtWith: 'objectstack-cli@3.4.0',
});
expect(parsed.builtAt).toBe('2026-04-26T00:00:00Z');
});
it('accepts optional payloadRef for future S3 indirection', () => {
const parsed = EnvironmentArtifactSchema.parse({
...minimal,
payloadRef: {
url: 'https://artifacts.objectstack.io/proj_x/commit_y.json',
checksum: { algorithm: 'sha256' as const, value: 'deadbeef' },
},
});
expect(parsed.payloadRef?.url).toContain('artifacts.objectstack.io');
});
});
describe('EnvironmentArtifactChecksumSchema', () => {
it('accepts lowercase hex values', () => {
expect(EnvironmentArtifactChecksumSchema.parse({ value: 'abc123' }).algorithm).toBe('sha256');
});
it('rejects uppercase / non-hex values', () => {
expect(EnvironmentArtifactChecksumSchema.safeParse({ value: 'ABC123' }).success).toBe(false);
expect(EnvironmentArtifactChecksumSchema.safeParse({ value: 'not-hex' }).success).toBe(false);
});
});
describe('EnvironmentArtifactFunctionSchema', () => {
it('accepts a typical inlined function', () => {
const parsed = EnvironmentArtifactFunctionSchema.parse({
name: 'on_account_create',
code: 'export default async (ctx) => {}',
});
expect(parsed.language).toBe('javascript');
});
it('rejects function names that are not snake_case', () => {
expect(
EnvironmentArtifactFunctionSchema.safeParse({ name: 'OnAccountCreate', code: '' }).success,
).toBe(false);
});
});
describe('EnvironmentArtifactManifestSchema', () => {
it('accepts an empty manifest', () => {
expect(EnvironmentArtifactManifestSchema.parse({})).toEqual({});
});
it('accepts plugins, drivers and engine constraints', () => {
const parsed = EnvironmentArtifactManifestSchema.parse({
plugins: [{ id: '@objectstack/plugin-auth', version: '^3.0.0' }],
drivers: [{ id: '@objectstack/driver-sql' }],
engine: { objectstack: '>=3.0.0' },
});
expect(parsed.plugins?.[0].id).toBe('@objectstack/plugin-auth');
expect(parsed.engine?.objectstack).toBe('>=3.0.0');
});
it('rejects malformed engine version ranges', () => {
expect(
EnvironmentArtifactManifestSchema.safeParse({ engine: { objectstack: 'not-a-range' } }).success,
).toBe(false);
});
});