@aigne/afs-compute-abstraction 1.11.0-beta.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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Compute Abstraction Types Tests
3
+ */
4
+ import { describe, expect, test } from "bun:test";
5
+ import { COMPUTE_STATES, computeInstanceSchema } from "../src/types.js";
6
+ describe("ComputeInstance type", () => {
7
+ describe("ComputeInstanceState", () => {
8
+ test("defines all expected states", () => {
9
+ expect(COMPUTE_STATES).toContain("running");
10
+ expect(COMPUTE_STATES).toContain("stopped");
11
+ expect(COMPUTE_STATES).toContain("pending");
12
+ expect(COMPUTE_STATES).toContain("terminated");
13
+ expect(COMPUTE_STATES).toContain("stopping");
14
+ expect(COMPUTE_STATES).toContain("unknown");
15
+ });
16
+ });
17
+ describe("computeInstanceSchema", () => {
18
+ test("validates minimal instance", () => {
19
+ const instance = {
20
+ id: "i-1234567890abcdef0",
21
+ name: "my-instance",
22
+ state: "running",
23
+ provider: "ec2",
24
+ instanceType: "t2.micro",
25
+ platformRef: {
26
+ consoleUrl: "https://console.aws.amazon.com/ec2",
27
+ afsPath: "/instances/my-instance",
28
+ },
29
+ };
30
+ const result = computeInstanceSchema.safeParse(instance);
31
+ expect(result.success).toBe(true);
32
+ });
33
+ test("validates full instance", () => {
34
+ const instance = {
35
+ id: "i-1234567890abcdef0",
36
+ name: "my-instance",
37
+ state: "running",
38
+ provider: "ec2",
39
+ instanceType: "t2.micro",
40
+ vcpus: 1,
41
+ memoryGb: 1,
42
+ publicIp: "54.123.45.67",
43
+ privateIp: "10.0.0.5",
44
+ launchTime: new Date("2024-01-01T00:00:00Z"),
45
+ platformRef: {
46
+ consoleUrl: "https://console.aws.amazon.com/ec2",
47
+ afsPath: "/instances/my-instance",
48
+ },
49
+ aws: {
50
+ instanceId: "i-1234567890abcdef0",
51
+ availabilityZone: "us-east-1a",
52
+ },
53
+ };
54
+ const result = computeInstanceSchema.safeParse(instance);
55
+ expect(result.success).toBe(true);
56
+ });
57
+ test("rejects instance without required fields", () => {
58
+ const instance = {
59
+ id: "i-123",
60
+ // missing name, state, provider, instanceType, platformRef
61
+ };
62
+ const result = computeInstanceSchema.safeParse(instance);
63
+ expect(result.success).toBe(false);
64
+ });
65
+ test("rejects invalid state", () => {
66
+ const instance = {
67
+ id: "i-123",
68
+ name: "my-instance",
69
+ state: "invalid-state",
70
+ provider: "ec2",
71
+ instanceType: "t2.micro",
72
+ platformRef: {
73
+ consoleUrl: "https://console.aws.amazon.com/ec2",
74
+ afsPath: "/instances/my-instance",
75
+ },
76
+ };
77
+ const result = computeInstanceSchema.safeParse(instance);
78
+ expect(result.success).toBe(false);
79
+ });
80
+ test("rejects invalid provider", () => {
81
+ const instance = {
82
+ id: "i-123",
83
+ name: "my-instance",
84
+ state: "running",
85
+ provider: "invalid-provider",
86
+ instanceType: "t2.micro",
87
+ platformRef: {
88
+ consoleUrl: "https://console.aws.amazon.com/ec2",
89
+ afsPath: "/instances/my-instance",
90
+ },
91
+ };
92
+ const result = computeInstanceSchema.safeParse(instance);
93
+ expect(result.success).toBe(false);
94
+ });
95
+ });
96
+ });
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@aigne/afs-compute-abstraction",
3
+ "version": "1.11.0-beta.6",
4
+ "description": "Compute abstraction layer for AFS - unified interface for EC2, GCE instances",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./types": {
14
+ "types": "./dist/types.d.ts",
15
+ "import": "./dist/types.js"
16
+ },
17
+ "./ec2": {
18
+ "types": "./dist/providers/ec2.d.ts",
19
+ "import": "./dist/providers/ec2.js"
20
+ },
21
+ "./gce": {
22
+ "types": "./dist/providers/gce.d.ts",
23
+ "import": "./dist/providers/gce.js"
24
+ }
25
+ },
26
+ "dependencies": {
27
+ "zod": "^3.24.4",
28
+ "@aigne/afs": "1.11.0-beta.6"
29
+ },
30
+ "devDependencies": {
31
+ "@aigne/afs-ec2": "1.11.0-beta.6",
32
+ "@aigne/afs-gce": "1.11.0-beta.6",
33
+ "@aigne/typescript-config": "0.0.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@aigne/afs-ec2": "1.11.0-beta.6",
37
+ "@aigne/afs-gce": "1.11.0-beta.6"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "@aigne/afs-ec2": {
41
+ "optional": true
42
+ },
43
+ "@aigne/afs-gce": {
44
+ "optional": true
45
+ }
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "LICENSE"
50
+ ],
51
+ "keywords": [
52
+ "afs",
53
+ "compute",
54
+ "ec2",
55
+ "gce",
56
+ "abstraction",
57
+ "cloud"
58
+ ],
59
+ "author": "AIGNE",
60
+ "license": "See LICENSE file",
61
+ "scripts": {
62
+ "build": "tsc",
63
+ "check-types": "tsc --noEmit",
64
+ "test": "bun test"
65
+ }
66
+ }