@grada-run/grada 0.0.1 → 0.33.0
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/.github/workflows/deploy-docs.yml +37 -0
- package/.github/workflows/e2e.yml +73 -0
- package/.github/workflows/iac-validation.yml +303 -0
- package/.github/workflows/publish.yml +68 -0
- package/.github/workflows/sync-bedrock-models.yml +57 -0
- package/.github/workflows/test.yml +43 -0
- package/.muserules +31 -0
- package/LICENSE +21 -0
- package/README.md +193 -3
- package/apps/docs/.astro/collections/docs.schema.json +644 -0
- package/apps/docs/.astro/content-assets.mjs +4 -0
- package/apps/docs/.astro/content-modules.mjs +4 -0
- package/apps/docs/.astro/content.d.ts +179 -0
- package/apps/docs/.astro/data-store.json +1 -0
- package/apps/docs/.astro/dev.json +14 -0
- package/apps/docs/.astro/settings.json +5 -0
- package/apps/docs/.astro/types.d.ts +2 -0
- package/apps/docs/astro.config.mjs +97 -0
- package/apps/docs/package.json +17 -0
- package/apps/docs/src/content/docs/adrs/0001-s3-native-state-locking.md +37 -0
- package/apps/docs/src/content/docs/adrs/0002-eject-mechanism-pure-iac.md +39 -0
- package/apps/docs/src/content/docs/adrs/0003-sync-ai-context-strategy.md +48 -0
- package/apps/docs/src/content/docs/adrs/0004-iac-driven-diagnostic-context.md +37 -0
- package/apps/docs/src/content/docs/adrs/0005-ecs-fargate-alb-runtime-target.md +38 -0
- package/apps/docs/src/content/docs/adrs/0006-github-oidc-no-stored-keys.md +37 -0
- package/apps/docs/src/content/docs/adrs/0007-framework-detection-with-fallback.md +37 -0
- package/apps/docs/src/content/docs/adrs/0008-secrets-names-in-git-values-in-aws.md +37 -0
- package/apps/docs/src/content/docs/adrs/0009-regenerate-with-backup-on-rerun.md +37 -0
- package/apps/docs/src/content/docs/adrs/0010-advisory-only-security-scans.md +37 -0
- package/apps/docs/src/content/docs/cli/add.md +85 -0
- package/apps/docs/src/content/docs/cli/apply.md +35 -0
- package/apps/docs/src/content/docs/cli/db.md +200 -0
- package/apps/docs/src/content/docs/cli/destroy.md +35 -0
- package/apps/docs/src/content/docs/cli/diagnose.md +37 -0
- package/apps/docs/src/content/docs/cli/doctor.md +28 -0
- package/apps/docs/src/content/docs/cli/domain.md +57 -0
- package/apps/docs/src/content/docs/cli/drift.md +40 -0
- package/apps/docs/src/content/docs/cli/eject.md +33 -0
- package/apps/docs/src/content/docs/cli/exec.md +49 -0
- package/apps/docs/src/content/docs/cli/gc.md +37 -0
- package/apps/docs/src/content/docs/cli/init.md +72 -0
- package/apps/docs/src/content/docs/cli/logs.md +39 -0
- package/apps/docs/src/content/docs/cli/rollback.md +51 -0
- package/apps/docs/src/content/docs/cli/secrets.md +73 -0
- package/apps/docs/src/content/docs/cli/sleep.md +53 -0
- package/apps/docs/src/content/docs/cli/status.md +34 -0
- package/apps/docs/src/content/docs/cli/sync-ai.md +27 -0
- package/apps/docs/src/content/docs/guides/architecture.md +87 -0
- package/apps/docs/src/content/docs/guides/aws-credentials.md +72 -0
- package/apps/docs/src/content/docs/guides/background-workers.md +45 -0
- package/apps/docs/src/content/docs/guides/cicd-pipeline.md +64 -0
- package/apps/docs/src/content/docs/guides/database-connections.md +64 -0
- package/apps/docs/src/content/docs/guides/docker-compose.md +37 -0
- package/apps/docs/src/content/docs/guides/dockerfiles.md +46 -0
- package/apps/docs/src/content/docs/guides/ephemeral-pr-previews.md +39 -0
- package/apps/docs/src/content/docs/guides/examples.md +50 -0
- package/apps/docs/src/content/docs/guides/frameworks.md +88 -0
- package/apps/docs/src/content/docs/guides/headless.md +87 -0
- package/apps/docs/src/content/docs/guides/quickstart.md +52 -0
- package/apps/docs/src/content/docs/guides/rerun-init.md +43 -0
- package/apps/docs/src/content/docs/guides/secrets-management.md +83 -0
- package/apps/docs/src/content/docs/guides/understanding-your-bill.md +63 -0
- package/apps/docs/src/content/docs/index.mdx +103 -0
- package/apps/docs/src/content/docs/migrations/astro-vercel-to-aws.md +55 -0
- package/apps/docs/src/content/docs/migrations/heroku-procfile-to-aws.md +41 -0
- package/apps/docs/src/content/docs/migrations/nextjs-vercel-to-aws.md +51 -0
- package/apps/docs/src/content/docs/migrations/sveltekit-vercel-to-aws.md +63 -0
- package/apps/docs/src/content/docs/roadmap.md +99 -0
- package/apps/docs/src/content/docs/testing-strategy.md +37 -0
- package/apps/docs/src/content.config.ts +7 -0
- package/apps/docs/src/custom.css +14 -0
- package/apps/docs/tsconfig.json +6 -0
- package/bin/cli.js +140 -0
- package/package.json +107 -7
- package/scripts/sync-bedrock-models.js +22 -0
- package/scripts/test-iac.js +261 -0
- package/specs/add-redis-sqs-bedrock.md +128 -0
- package/specs/add-storage-dynamodb.md +106 -0
- package/specs/bedrock-model-catalog.md +131 -0
- package/specs/ci-pipeline.md +17 -0
- package/specs/cost-transparency.md +115 -0
- package/specs/custom-domains-and-ses.md +153 -0
- package/specs/database-suite-expansion.md +151 -0
- package/specs/db-connect.md +69 -0
- package/specs/db-lifecycle-migrations.md +159 -0
- package/specs/dependency-aware-init.md +176 -0
- package/specs/deployment-safety.md +170 -0
- package/specs/diagnose.md +16 -0
- package/specs/docs-hub.md +16 -0
- package/specs/dx-polish.md +46 -0
- package/specs/e2e-testing.md +50 -0
- package/specs/exec.md +25 -0
- package/specs/finops-cron-drift.md +161 -0
- package/specs/gc.md +26 -0
- package/specs/integration-suite.md +16 -0
- package/specs/logs.md +32 -0
- package/specs/rollback-live-polling.md +40 -0
- package/specs/secrets-pull-audit.md +51 -0
- package/specs/serverless-lambda-target.md +133 -0
- package/specs/status.md +31 -0
- package/specs/telemetry-and-spawn-hardening.md +69 -0
- package/specs/telemetry-hardening.md +35 -0
- package/specs/test-suite-deduplication.md +42 -0
- package/src/commands/add.js +1111 -0
- package/src/commands/apply.js +214 -0
- package/src/commands/db/backup.js +229 -0
- package/src/commands/db/connect.js +304 -0
- package/src/commands/db/enable-vector.js +344 -0
- package/src/commands/db/import.js +604 -0
- package/src/commands/db/migrate.js +477 -0
- package/src/commands/db/restore.js +361 -0
- package/src/commands/db.js +87 -0
- package/src/commands/destroy.js +217 -0
- package/src/commands/diagnose.js +460 -0
- package/src/commands/doctor.js +109 -0
- package/src/commands/domain.js +685 -0
- package/src/commands/drift.js +243 -0
- package/src/commands/eject.js +130 -0
- package/src/commands/exec.js +222 -0
- package/src/commands/gc.js +250 -0
- package/src/commands/init.js +649 -0
- package/src/commands/logs.js +256 -0
- package/src/commands/rollback.js +323 -0
- package/src/commands/secrets.js +485 -0
- package/src/commands/sleep.js +347 -0
- package/src/commands/status.js +309 -0
- package/src/commands/sync-ai.js +115 -0
- package/src/commands/wake.js +337 -0
- package/src/core/parser.js +128 -0
- package/src/core/telemetry.js +244 -0
- package/src/data/bedrock-models.json +896 -0
- package/src/utils/addons.js +126 -0
- package/src/utils/ai-rules.js +59 -0
- package/src/utils/args.js +91 -0
- package/src/utils/aws.js +178 -0
- package/src/utils/backup.js +69 -0
- package/src/utils/bedrock-catalog.js +511 -0
- package/src/utils/capabilities.js +500 -0
- package/src/utils/command.js +78 -0
- package/src/utils/db-tunnel.js +164 -0
- package/src/utils/detector.js +298 -0
- package/src/utils/dockerCompose.js +65 -0
- package/src/utils/domains.js +73 -0
- package/src/utils/ecs-runner.js +289 -0
- package/src/utils/ecs.js +92 -0
- package/src/utils/frameworks.js +55 -0
- package/src/utils/generator.js +527 -0
- package/src/utils/hcl.js +426 -0
- package/src/utils/lambda-ecr.js +185 -0
- package/src/utils/prompts.js +278 -0
- package/src/utils/rds.js +131 -0
- package/src/utils/resolvers.js +174 -0
- package/src/utils/sleep-state.js +140 -0
- package/src/utils/sleep-targets.js +139 -0
- package/src/utils/system.js +42 -0
- package/src/utils/terraform.js +70 -0
- package/src/utils/visualizer.js +381 -0
- package/src/utils/warnings.js +49 -0
- package/templates/README.md +150 -0
- package/templates/docker/django.Dockerfile +40 -0
- package/templates/docker/go.Dockerfile +23 -0
- package/templates/docker/nestjs.Dockerfile +33 -0
- package/templates/docker/nextjs.Dockerfile +55 -0
- package/templates/docker/node.Dockerfile +24 -0
- package/templates/docker/nuxt.Dockerfile +47 -0
- package/templates/docker/python.Dockerfile +38 -0
- package/templates/docker/rails.Dockerfile +59 -0
- package/templates/docker/static.Dockerfile +32 -0
- package/templates/docker/svelte.Dockerfile +52 -0
- package/templates/github/deploy-lambda.yml +120 -0
- package/templates/github/deploy.yml +138 -0
- package/templates/github/drift.yml +112 -0
- package/templates/github/preview-lambda.yml +86 -0
- package/templates/github/preview.yml +69 -0
- package/templates/github/teardown.yml +43 -0
- package/templates/terraform/addons/bedrock.tf +34 -0
- package/templates/terraform/addons/cron-lambda.tf +78 -0
- package/templates/terraform/addons/cron.tf +101 -0
- package/templates/terraform/addons/dynamodb.tf +73 -0
- package/templates/terraform/addons/redis.tf +64 -0
- package/templates/terraform/addons/s3.tf +143 -0
- package/templates/terraform/addons/ses.tf +73 -0
- package/templates/terraform/addons/sqs.tf +67 -0
- package/templates/terraform/backend.tf +22 -0
- package/templates/terraform/cloudfront-lambda.tf +80 -0
- package/templates/terraform/cloudfront.tf +80 -0
- package/templates/terraform/database-aurora-postgresql.tf +92 -0
- package/templates/terraform/database-mysql.tf +72 -0
- package/templates/terraform/database.tf +71 -0
- package/templates/terraform/main-lambda.tf +229 -0
- package/templates/terraform/main.tf +296 -0
- package/templates/terraform/network.tf +95 -0
- package/templates/terraform/oidc.tf +64 -0
- package/templates/terraform/secrets.tf +31 -0
- package/templates/terraform/worker.tf +69 -0
- package/tests/__snapshots__/generator.test.js.snap +9633 -0
- package/tests/add.test.js +2018 -0
- package/tests/ai.test.js +91 -0
- package/tests/apply.test.js +446 -0
- package/tests/args.test.js +86 -0
- package/tests/aws.test.js +244 -0
- package/tests/capabilities.test.js +304 -0
- package/tests/cli.test.js +29 -0
- package/tests/command.test.js +99 -0
- package/tests/commands-import.test.js +74 -0
- package/tests/db.test.js +2673 -0
- package/tests/destroy.test.js +365 -0
- package/tests/detector.test.js +79 -0
- package/tests/diagnose.test.js +765 -0
- package/tests/doctor.test.js +195 -0
- package/tests/domain.test.js +882 -0
- package/tests/drift.test.js +228 -0
- package/tests/e2e/helpers.js +122 -0
- package/tests/e2e/tier0.e2e.test.js +142 -0
- package/tests/e2e/tier1.live.e2e.test.js +118 -0
- package/tests/ecs.test.js +130 -0
- package/tests/eject.test.js +65 -0
- package/tests/exec.test.js +366 -0
- package/tests/gc.test.js +466 -0
- package/tests/generator.test.js +794 -0
- package/tests/headless.test.js +491 -0
- package/tests/helpers/clack.js +103 -0
- package/tests/helpers/console.js +41 -0
- package/tests/helpers/telemetry.js +37 -0
- package/tests/helpers/tmpdir.js +36 -0
- package/tests/lambda-ecr.test.js +185 -0
- package/tests/logs.test.js +436 -0
- package/tests/parser.test.js +160 -0
- package/tests/rds.test.js +244 -0
- package/tests/resolvers.test.js +279 -0
- package/tests/rollback.test.js +670 -0
- package/tests/secrets.test.js +729 -0
- package/tests/sleep-wake.test.js +998 -0
- package/tests/status.test.js +356 -0
- package/tests/system.test.js +70 -0
- package/tests/telemetry.test.js +520 -0
- package/tests/terraform.test.js +84 -0
- package/tests/visualizer.test.js +480 -0
- package/vitest.config.js +10 -0
- package/vitest.e2e.tier0.config.js +8 -0
- package/vitest.e2e.tier1.config.js +8 -0
- package/index.js +0 -2
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
// NOTE: helper imports must stay above src imports: vi.mock factories run
|
|
3
|
+
// during module evaluation and need the factories initialized.
|
|
4
|
+
import { clackPromptsMockFactory } from './helpers/clack.js';
|
|
5
|
+
import { telemetryMockFactory } from './helpers/telemetry.js';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import { runStatus, runLambdaStatus, parseStatusArgs, getServiceHealth, getLambdaHealth, DEGRADED_MESSAGE } from '../src/commands/status.js';
|
|
10
|
+
import { runDiagnose } from '../src/commands/diagnose.js';
|
|
11
|
+
import { trackEvent } from '../src/core/telemetry.js';
|
|
12
|
+
|
|
13
|
+
vi.mock('../src/commands/diagnose.js', () => ({
|
|
14
|
+
runDiagnose: vi.fn().mockResolvedValue({ healthy: false }),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock('@clack/prompts', () => clackPromptsMockFactory());
|
|
18
|
+
|
|
19
|
+
vi.mock('../src/core/telemetry.js', (importOriginal) => telemetryMockFactory(importOriginal));
|
|
20
|
+
|
|
21
|
+
function mockEcsClient(serviceDesc) {
|
|
22
|
+
return { send: vi.fn().mockResolvedValue({ services: [serviceDesc] }) };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function mockCloudWatchClient(alarms = []) {
|
|
26
|
+
return { send: vi.fn().mockResolvedValue({ MetricAlarms: alarms, CompositeAlarms: [] }) };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const healthyService = {
|
|
30
|
+
serviceName: 'myapp-service',
|
|
31
|
+
status: 'ACTIVE',
|
|
32
|
+
desiredCount: 2,
|
|
33
|
+
runningCount: 2,
|
|
34
|
+
pendingCount: 0,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe('status: CLI args', () => {
|
|
38
|
+
it('parses --region and --json', () => {
|
|
39
|
+
expect(parseStatusArgs(['status', '--region', 'eu-west-1', '--json'])).toEqual({
|
|
40
|
+
region: 'eu-west-1',
|
|
41
|
+
json: true,
|
|
42
|
+
});
|
|
43
|
+
expect(parseStatusArgs(['status', '--region=us-west-2'])).toEqual({ region: 'us-west-2' });
|
|
44
|
+
expect(parseStatusArgs(['status'])).toEqual({});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('status: health calculation', () => {
|
|
49
|
+
it('is healthy when running matches desired and alarms are OK', () => {
|
|
50
|
+
const health = getServiceHealth(healthyService, [{ AlarmName: 'a', StateValue: 'OK' }]);
|
|
51
|
+
expect(health.healthy).toBe(true);
|
|
52
|
+
expect(health.alarmed).toHaveLength(0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('is unhealthy when running is below desired', () => {
|
|
56
|
+
const health = getServiceHealth({ ...healthyService, runningCount: 1 }, []);
|
|
57
|
+
expect(health.healthy).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('is unhealthy when any alarm is in ALARM state', () => {
|
|
61
|
+
const health = getServiceHealth(healthyService, [{ AlarmName: 'x', StateValue: 'ALARM' }]);
|
|
62
|
+
expect(health.healthy).toBe(false);
|
|
63
|
+
expect(health.alarmed).toHaveLength(1);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('Command: status (mocked ECS + CloudWatch)', () => {
|
|
68
|
+
const savedEnv = { ...process.env };
|
|
69
|
+
let exitSpy;
|
|
70
|
+
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
vi.clearAllMocks();
|
|
73
|
+
delete process.env.AWS_REGION;
|
|
74
|
+
delete process.env.ECS_CLUSTER;
|
|
75
|
+
delete process.env.ECS_SERVICE;
|
|
76
|
+
delete process.env.ECS_LOG_GROUP;
|
|
77
|
+
exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => { });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
process.env = { ...savedEnv };
|
|
82
|
+
exitSpy.mockRestore();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('exits cleanly with a green dashboard when healthy', async () => {
|
|
86
|
+
const ecsClient = mockEcsClient(healthyService);
|
|
87
|
+
const cloudWatchClient = mockCloudWatchClient([{ AlarmName: 'myapp-high-5xx-errors', StateValue: 'OK' }]);
|
|
88
|
+
|
|
89
|
+
const output = [];
|
|
90
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation((...args) => {
|
|
91
|
+
output.push(args.join(' '));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const result = await runStatus({ projectName: 'myapp', region: 'us-east-2', ecsClient, cloudWatchClient });
|
|
96
|
+
expect(result.healthy).toBe(true);
|
|
97
|
+
expect(result.service.runningCount).toBe(2);
|
|
98
|
+
expect(result.service.desiredCount).toBe(2);
|
|
99
|
+
expect(runDiagnose).not.toHaveBeenCalled();
|
|
100
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
101
|
+
const text = output.join('\n');
|
|
102
|
+
expect(text).toContain('myapp-service');
|
|
103
|
+
expect(text).toContain('2/2');
|
|
104
|
+
expect(text).toContain('[OK]');
|
|
105
|
+
} finally {
|
|
106
|
+
consoleSpy.mockRestore();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('runs automated diagnostics and exits 1 on a crash loop', async () => {
|
|
111
|
+
const ecsClient = mockEcsClient({ ...healthyService, runningCount: 1, pendingCount: 1 });
|
|
112
|
+
const cloudWatchClient = mockCloudWatchClient([]);
|
|
113
|
+
|
|
114
|
+
const output = [];
|
|
115
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation((...args) => {
|
|
116
|
+
output.push(args.join(' '));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const result = await runStatus({ projectName: 'myapp', region: 'us-east-2', ecsClient, cloudWatchClient });
|
|
121
|
+
expect(result.healthy).toBe(false);
|
|
122
|
+
expect(output.join('\n')).toContain(DEGRADED_MESSAGE);
|
|
123
|
+
expect(runDiagnose).toHaveBeenCalledWith(
|
|
124
|
+
expect.objectContaining({ cluster: 'myapp-cluster', region: 'us-east-2', logGroup: '/ecs/myapp' })
|
|
125
|
+
);
|
|
126
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
127
|
+
} finally {
|
|
128
|
+
consoleSpy.mockRestore();
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('hands off to diagnose when a 5XX alarm fires', async () => {
|
|
133
|
+
const ecsClient = mockEcsClient(healthyService);
|
|
134
|
+
const cloudWatchClient = mockCloudWatchClient([
|
|
135
|
+
{ AlarmName: 'myapp-high-5xx-errors', StateValue: 'ALARM' },
|
|
136
|
+
]);
|
|
137
|
+
|
|
138
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
139
|
+
try {
|
|
140
|
+
const result = await runStatus({ projectName: 'myapp', region: 'us-east-2', ecsClient, cloudWatchClient });
|
|
141
|
+
expect(result.healthy).toBe(false);
|
|
142
|
+
expect(runDiagnose).toHaveBeenCalledTimes(1);
|
|
143
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
144
|
+
} finally {
|
|
145
|
+
consoleSpy.mockRestore();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('--json prints the raw payload and disables auto-diagnose', async () => {
|
|
150
|
+
const ecsClient = mockEcsClient({ ...healthyService, runningCount: 0 });
|
|
151
|
+
const cloudWatchClient = mockCloudWatchClient([]);
|
|
152
|
+
|
|
153
|
+
const output = [];
|
|
154
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation((...args) => {
|
|
155
|
+
output.push(args.join(' '));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const result = await runStatus({ projectName: 'myapp', region: 'us-east-2', json: true, ecsClient, cloudWatchClient });
|
|
160
|
+
expect(runDiagnose).not.toHaveBeenCalled();
|
|
161
|
+
expect(exitSpy).not.toHaveBeenCalled();
|
|
162
|
+
const payload = JSON.parse(output.join('\n'));
|
|
163
|
+
expect(payload.healthy).toBe(false);
|
|
164
|
+
expect(payload.service.runningCount).toBe(0);
|
|
165
|
+
expect(result.healthy).toBe(false);
|
|
166
|
+
} finally {
|
|
167
|
+
consoleSpy.mockRestore();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('prints SSO recovery guidance and exits 1 on expired sessions', async () => {
|
|
172
|
+
const error = new Error('Invalid token');
|
|
173
|
+
error.name = 'UnrecognizedClientException';
|
|
174
|
+
const ecsClient = { send: vi.fn().mockRejectedValue(error) };
|
|
175
|
+
const cloudWatchClient = mockCloudWatchClient([]);
|
|
176
|
+
|
|
177
|
+
const output = [];
|
|
178
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation((...args) => {
|
|
179
|
+
output.push(args.join(' '));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
await runStatus({ projectName: 'myapp', region: 'us-east-2', ecsClient, cloudWatchClient, spawnSyncImpl: () => ({ status: 0 }) });
|
|
184
|
+
expect(output.join('\n')).toContain('aws sso login');
|
|
185
|
+
expect(runDiagnose).not.toHaveBeenCalled();
|
|
186
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
187
|
+
} finally {
|
|
188
|
+
consoleSpy.mockRestore();
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('is wired into bin/cli.js with diagnose hidden from help', () => {
|
|
193
|
+
const cliPath = path.resolve(__dirname, '../bin/cli.js');
|
|
194
|
+
const content = fs.readFileSync(cliPath, 'utf8');
|
|
195
|
+
expect(content).toContain('runStatus');
|
|
196
|
+
expect(content).toContain("'status'");
|
|
197
|
+
|
|
198
|
+
const helpBlock = content.match(/HELP_TEXT = \[([\s\S]*?)\];/);
|
|
199
|
+
expect(helpBlock).not.toBeNull();
|
|
200
|
+
expect(helpBlock[1]).toContain('status');
|
|
201
|
+
expect(helpBlock[1]).not.toContain('diagnose');
|
|
202
|
+
expect(helpBlock[1]).not.toContain('wtf');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('exits 0 and prints guidance when the service does not exist', async () => {
|
|
206
|
+
const ecsClient = { send: vi.fn().mockResolvedValue({ services: [] }) };
|
|
207
|
+
const cloudWatchClient = mockCloudWatchClient([]);
|
|
208
|
+
|
|
209
|
+
const output = [];
|
|
210
|
+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation((...args) => {
|
|
211
|
+
output.push(args.join(' '));
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
await runStatus({ projectName: 'myapp', region: 'us-east-2', ecsClient, cloudWatchClient });
|
|
216
|
+
|
|
217
|
+
const text = output.join('\n');
|
|
218
|
+
expect(text).toContain('does not exist or is inactive');
|
|
219
|
+
expect(text).toContain('npx grada-run apply');
|
|
220
|
+
|
|
221
|
+
expect(runDiagnose).not.toHaveBeenCalled();
|
|
222
|
+
expect(exitSpy).toHaveBeenCalledWith(0);
|
|
223
|
+
} finally {
|
|
224
|
+
consoleSpy.mockRestore();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('status: fuzzer hardening', () => {
|
|
230
|
+
let exitSpy;
|
|
231
|
+
let consoleSpy;
|
|
232
|
+
|
|
233
|
+
beforeEach(() => {
|
|
234
|
+
vi.clearAllMocks();
|
|
235
|
+
exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => { });
|
|
236
|
+
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
afterEach(() => {
|
|
240
|
+
exitSpy.mockRestore();
|
|
241
|
+
consoleSpy.mockRestore();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('routes unresolvable projects through PROJECT_NOT_INITIALIZED', async () => {
|
|
245
|
+
const cwdSpy = vi.spyOn(process, 'cwd').mockImplementation(() => { throw new Error('deleted'); });
|
|
246
|
+
try {
|
|
247
|
+
const result = await runStatus(null);
|
|
248
|
+
expect(result).toEqual({ ok: false, reason: 'project-not-initialized' });
|
|
249
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
250
|
+
expect(trackEvent).toHaveBeenCalledWith('status_run', expect.objectContaining({
|
|
251
|
+
success: false,
|
|
252
|
+
error_code: 'PROJECT_NOT_INITIALIZED',
|
|
253
|
+
}));
|
|
254
|
+
} finally {
|
|
255
|
+
cwdSpy.mockRestore();
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it.each([null, 42, true, { port: 'string' }])('parseStatusArgs(%s) returns defaults', (bad) => {
|
|
260
|
+
expect(parseStatusArgs(bad)).toEqual({});
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('status: lambda target (mocked AWS CLI)', () => {
|
|
265
|
+
let exitSpy;
|
|
266
|
+
let consoleSpy;
|
|
267
|
+
|
|
268
|
+
beforeEach(() => {
|
|
269
|
+
vi.clearAllMocks();
|
|
270
|
+
exitSpy = vi.spyOn(process, 'exit').mockImplementation(() => { });
|
|
271
|
+
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
afterEach(() => {
|
|
275
|
+
exitSpy.mockRestore();
|
|
276
|
+
consoleSpy.mockRestore();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const ACTIVE = JSON.stringify({
|
|
280
|
+
Configuration: {
|
|
281
|
+
State: 'Active',
|
|
282
|
+
LastUpdateStatus: 'Successful',
|
|
283
|
+
LastModified: '2026-01-01T00:00:00Z',
|
|
284
|
+
MemorySize: 512,
|
|
285
|
+
Timeout: 30,
|
|
286
|
+
Code: { ImageUri: '123.dkr.ecr.us-east-2.amazonaws.com/myapp-repo:abc1234' },
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
function cliWith(stdout, status = 0) {
|
|
291
|
+
return vi.fn(() => ({ status, stdout, stderr: '' }));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
it('judges health from function State and LastUpdateStatus', () => {
|
|
295
|
+
expect(getLambdaHealth({ State: 'Active', LastUpdateStatus: 'Successful' }).healthy).toBe(true);
|
|
296
|
+
expect(getLambdaHealth({ State: 'Active', LastUpdateStatus: 'Failed' }).healthy).toBe(false);
|
|
297
|
+
expect(getLambdaHealth({ State: 'Pending', LastUpdateStatus: 'Successful' }).healthy).toBe(false);
|
|
298
|
+
expect(getLambdaHealth({}).healthy).toBe(false);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('reports a healthy function without touching ECS', async () => {
|
|
302
|
+
const spawnSyncImpl = cliWith(ACTIVE);
|
|
303
|
+
const result = await runLambdaStatus({ projectName: 'myapp', region: 'us-east-2', spawnSyncImpl });
|
|
304
|
+
expect(result.healthy).toBe(true);
|
|
305
|
+
expect(result.computeTarget).toBe('lambda');
|
|
306
|
+
expect(result.function.name).toBe('myapp-fn');
|
|
307
|
+
expect(spawnSyncImpl).toHaveBeenCalledWith(
|
|
308
|
+
'aws',
|
|
309
|
+
expect.arrayContaining(['lambda', 'get-function', '--function-name', 'myapp-fn']),
|
|
310
|
+
expect.anything()
|
|
311
|
+
);
|
|
312
|
+
expect(trackEvent).toHaveBeenCalledWith('status_run', expect.objectContaining({ healthy: true, success: true }));
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it('supports --json and explicit function names', async () => {
|
|
316
|
+
const spawnSyncImpl = cliWith(ACTIVE);
|
|
317
|
+
const result = await runLambdaStatus({ projectName: 'myapp', region: 'us-east-2', functionName: 'custom-fn', json: true, spawnSyncImpl });
|
|
318
|
+
expect(result.function.name).toBe('custom-fn');
|
|
319
|
+
expect(spawnSyncImpl.mock.calls[0][1]).toContain('custom-fn');
|
|
320
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('"computeTarget": "lambda"'));
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('runs diagnostics and exits 1 when degraded', async () => {
|
|
324
|
+
const failed = JSON.stringify({ Configuration: { State: 'Active', LastUpdateStatus: 'Failed' } });
|
|
325
|
+
const result = await runLambdaStatus({ projectName: 'myapp', region: 'us-east-2', spawnSyncImpl: cliWith(failed) });
|
|
326
|
+
expect(result.healthy).toBe(false);
|
|
327
|
+
expect(runDiagnose).toHaveBeenCalled();
|
|
328
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('guides missing functions to apply and missing CLIs to install', async () => {
|
|
332
|
+
const missing = vi.fn(() => ({ status: 254, stdout: '', stderr: 'ResourceNotFoundException' }));
|
|
333
|
+
const result = await runLambdaStatus({ projectName: 'myapp', region: 'us-east-2', json: true, spawnSyncImpl: missing });
|
|
334
|
+
expect(result).toMatchObject({ healthy: false, missing: true });
|
|
335
|
+
|
|
336
|
+
const noCli = vi.fn(() => ({ error: { code: 'ENOENT' } }));
|
|
337
|
+
await runLambdaStatus({ projectName: 'myapp', region: 'us-east-2', spawnSyncImpl: noCli });
|
|
338
|
+
expect(trackEvent).toHaveBeenCalledWith('status_run', expect.objectContaining({ error_code: 'AWS_CLI_MISSING' }));
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('dispatches lambda projects from runStatus', async () => {
|
|
342
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'status-lambda-test-'));
|
|
343
|
+
try {
|
|
344
|
+
fs.mkdirSync(path.join(dir, 'terraform'), { recursive: true });
|
|
345
|
+
fs.writeFileSync(
|
|
346
|
+
path.join(dir, 'terraform', 'main.tf'),
|
|
347
|
+
'locals {\n app_name = "myapp${local.env_suffix}"\n}\nresource "aws_lambda_function" "app" {}\n'
|
|
348
|
+
);
|
|
349
|
+
const result = await runStatus({ cwd: dir, region: 'us-east-2', spawnSyncImpl: cliWith(ACTIVE) });
|
|
350
|
+
expect(result.healthy).toBe(true);
|
|
351
|
+
expect(result.computeTarget).toBe('lambda');
|
|
352
|
+
} finally {
|
|
353
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { pollUntil, parseTimeoutSeconds } from '../src/utils/system.js';
|
|
3
|
+
|
|
4
|
+
describe('parseTimeoutSeconds', () => {
|
|
5
|
+
it('returns the default when omitted or blank', () => {
|
|
6
|
+
expect(parseTimeoutSeconds(undefined, 600)).toBe(600);
|
|
7
|
+
expect(parseTimeoutSeconds(null, 900)).toBe(900);
|
|
8
|
+
expect(parseTimeoutSeconds('', 600)).toBe(600);
|
|
9
|
+
expect(parseTimeoutSeconds(' ', 600)).toBe(600);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('parses positive integers', () => {
|
|
13
|
+
expect(parseTimeoutSeconds('60', 600)).toBe(60);
|
|
14
|
+
expect(parseTimeoutSeconds(' 120 ', 600)).toBe(120);
|
|
15
|
+
expect(parseTimeoutSeconds(30, 600)).toBe(30);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it.each(['0', '-5', 'abc', '60s', '1.5', '0x10'])('rejects %s', (value) => {
|
|
19
|
+
expect(parseTimeoutSeconds(value, 600)).toBeNull();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('pollUntil', () => {
|
|
24
|
+
it('resolves immediately when the first tick is done', async () => {
|
|
25
|
+
const sleepFn = vi.fn(() => Promise.resolve());
|
|
26
|
+
const outcome = await pollUntil({
|
|
27
|
+
intervalMs: 1000,
|
|
28
|
+
timeoutMs: 60000,
|
|
29
|
+
sleepFn,
|
|
30
|
+
nowFn: () => 0,
|
|
31
|
+
onTick: async () => ({ done: true, value: 'v' }),
|
|
32
|
+
});
|
|
33
|
+
expect(outcome).toEqual({ done: true, value: 'v' });
|
|
34
|
+
expect(sleepFn).not.toHaveBeenCalled();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('ticks until done, reporting elapsed time', async () => {
|
|
38
|
+
let now = 0;
|
|
39
|
+
const seen = [];
|
|
40
|
+
const outcome = await pollUntil({
|
|
41
|
+
intervalMs: 100,
|
|
42
|
+
timeoutMs: 10000,
|
|
43
|
+
sleepFn: async () => { now += 100; },
|
|
44
|
+
nowFn: () => now,
|
|
45
|
+
onTick: async ({ elapsedMs }) => {
|
|
46
|
+
seen.push(elapsedMs);
|
|
47
|
+
return seen.length >= 3 ? { done: true, value: 'late' } : { done: false };
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
expect(outcome).toEqual({ done: true, value: 'late' });
|
|
51
|
+
expect(seen).toEqual([0, 100, 200]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('times out without running the tick past the deadline', async () => {
|
|
55
|
+
let now = 0;
|
|
56
|
+
let ticks = 0;
|
|
57
|
+
const outcome = await pollUntil({
|
|
58
|
+
intervalMs: 100,
|
|
59
|
+
timeoutMs: 250,
|
|
60
|
+
sleepFn: async () => { now += 100; },
|
|
61
|
+
nowFn: () => now,
|
|
62
|
+
onTick: async () => {
|
|
63
|
+
ticks += 1;
|
|
64
|
+
return { done: false };
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
expect(outcome).toEqual({ timedOut: true });
|
|
68
|
+
expect(ticks).toBe(3);
|
|
69
|
+
});
|
|
70
|
+
});
|