@astrale-os/cli 1.0.0-beta.0 → 1.0.0-beta.10
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/README.md +23 -12
- package/dist/astrale.js +51494 -56307
- package/dist/public/connect-core.js +2028 -26846
- package/dist/public/keys/index.js +1755 -40694
- package/dist/public/paths/index.js +859 -39518
- package/dist/types/admin/binding.d.ts +19 -0
- package/dist/types/admin/instance/client.d.ts +22 -0
- package/dist/types/admin/instance/index.d.ts +2 -0
- package/dist/types/admin/instance/model.d.ts +5 -12
- package/dist/types/connection/auth.d.ts +3 -0
- package/dist/types/connection/call.d.ts +3 -0
- package/dist/types/connection/command.d.ts +27 -0
- package/dist/types/connection/credential.d.ts +14 -0
- package/dist/types/connection/errors.d.ts +1 -0
- package/dist/types/connection/exchange.d.ts +9 -0
- package/dist/types/connection/failure/classify.d.ts +2 -0
- package/dist/types/connection/failure/index.d.ts +5 -0
- package/dist/types/connection/failure/model.d.ts +25 -0
- package/dist/types/connection/failure/render.d.ts +3 -0
- package/dist/types/connection/index.d.ts +8 -0
- package/dist/types/connection/reasons.d.ts +37 -0
- package/dist/types/connection/self.d.ts +37 -0
- package/dist/types/connection/session.d.ts +31 -0
- package/dist/types/connection/target.d.ts +38 -0
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/lib/admin-instance.d.ts +17 -0
- package/dist/types/lib/admin-target.d.ts +6 -2
- package/dist/types/lib/failure-debug.d.ts +1 -0
- package/dist/types/lib/idp.d.ts +7 -0
- package/dist/types/lib/instance-target.d.ts +1 -1
- package/dist/types/lib/instance.d.ts +10 -2
- package/dist/types/lib/log.d.ts +5 -3
- package/dist/types/lib/meta.d.ts +2 -2
- package/dist/types/lib/proc.d.ts +43 -0
- package/dist/types/lib/self.d.ts +9 -0
- package/dist/types/lib/update.d.ts +131 -0
- package/package.json +8 -10
- package/src/__tests__/fixtures/publication.ts +20 -0
- package/src/admin/__tests__/binding.test.ts +31 -0
- package/src/admin/__tests__/fixture.ts +101 -0
- package/src/admin/binding.ts +98 -0
- package/src/admin/catalog/.spec/api.d.ts +2 -2
- package/src/admin/catalog/__tests__/client.test.ts +20 -49
- package/src/admin/catalog/client.ts +36 -32
- package/src/admin/catalog/model.ts +3 -4
- package/src/admin/graph/.spec/api.d.ts +4 -10
- package/src/admin/graph/nodes.ts +1 -1
- package/src/admin/instance/.spec/api.d.ts +2 -2
- package/src/admin/instance/__tests__/client.test.ts +40 -163
- package/src/admin/instance/client.ts +35 -137
- package/src/admin/instance/index.ts +1 -2
- package/src/admin/instance/model.ts +11 -20
- package/src/commands/__tests__/admin-instance.test.ts +11 -8
- package/src/commands/__tests__/auth-login.test.ts +54 -1
- package/src/commands/__tests__/call-describe.test.ts +46 -33
- package/src/commands/__tests__/call.test.ts +5 -1
- package/src/commands/__tests__/domain-install-operation.test.ts +12 -7
- package/src/commands/__tests__/domain-install-owned.test.ts +6 -2
- package/src/commands/__tests__/domain-list.test.ts +63 -4
- package/src/commands/__tests__/install-identity-override.test.ts +19 -19
- package/src/commands/__tests__/instance-list-rows.test.ts +1 -1
- package/src/commands/__tests__/instance-status.test.ts +139 -0
- package/src/commands/__tests__/read-commands.test.ts +35 -10
- package/src/commands/__tests__/studio-descriptor.test.ts +22 -0
- package/src/commands/__tests__/update.test.ts +95 -0
- package/src/commands/call-describe.ts +60 -68
- package/src/commands/call.ts +43 -56
- package/src/commands/domain/install.ts +13 -17
- package/src/commands/domain/list.ts +18 -13
- package/src/commands/domain/publish.ts +14 -11
- package/src/commands/domain/uninstall.ts +2 -2
- package/src/commands/get.ts +14 -15
- package/src/commands/identity/__tests__/register.test.ts +3 -3
- package/src/commands/identity/register.ts +5 -4
- package/src/commands/instance/create.ts +8 -16
- package/src/commands/instance/delete.ts +12 -9
- package/src/commands/instance/list.ts +2 -2
- package/src/commands/instance/status.ts +66 -20
- package/src/commands/instance/use.ts +16 -12
- package/src/commands/introspect.ts +9 -16
- package/src/commands/logs.ts +24 -25
- package/src/commands/mutate.ts +6 -5
- package/src/commands/query.ts +27 -30
- package/src/commands/studio.ts +20 -0
- package/src/commands/token.ts +8 -7
- package/src/commands/update.ts +68 -22
- package/src/commands/view.ts +7 -6
- package/src/connection/.spec/api.d.ts +7 -8
- package/src/connection/.spec/architecture.md +5 -4
- package/src/connection/.spec/flows/session.ts +2 -2
- package/src/connection/.spec/laws/connection.ts +6 -2
- package/src/connection/.spec/layout.ts +1 -0
- package/src/connection/__tests__/credential.test.ts +20 -1
- package/src/connection/__tests__/errors.test.ts +43 -32
- package/src/connection/__tests__/exchange.test.ts +36 -6
- package/src/connection/__tests__/failure-fixtures.ts +39 -0
- package/src/connection/__tests__/failure-safety.test.ts +75 -0
- package/src/connection/__tests__/self.test.ts +31 -11
- package/src/connection/__tests__/session.test.ts +3 -3
- package/src/connection/__tests__/target.test.ts +1 -0
- package/src/connection/auth.ts +13 -0
- package/src/connection/call.ts +1 -1
- package/src/connection/credential.ts +2 -2
- package/src/connection/errors.ts +1 -355
- package/src/connection/exchange.ts +52 -27
- package/src/connection/failure/classify.ts +110 -0
- package/src/connection/failure/index.ts +18 -0
- package/src/connection/failure/model.ts +28 -0
- package/src/connection/failure/render.ts +116 -0
- package/src/connection/reasons.ts +16 -0
- package/src/connection/self.ts +39 -21
- package/src/connection/session.ts +19 -8
- package/src/errors.ts +3 -2
- package/src/graph/.spec/api.d.ts +12 -5
- package/src/graph/.spec/layout.ts +9 -1
- package/src/graph/__tests__/mutation.test.ts +2 -2
- package/src/graph/__tests__/query.test.ts +25 -6
- package/src/graph/class.ts +30 -0
- package/src/graph/index.ts +1 -0
- package/src/graph/query.ts +21 -32
- package/src/identity/.spec/api.d.ts +2 -2
- package/src/identity/__tests__/registration.test.ts +1 -1
- package/src/identity/registration.ts +3 -3
- package/src/keys/__tests__/keys.test.ts +4 -0
- package/src/keys/credential.ts +1 -0
- package/src/lib/__tests__/admin-target.test.ts +12 -0
- package/src/lib/__tests__/command-dx.test.ts +1 -1
- package/src/lib/__tests__/domain-publication.test.ts +138 -0
- package/src/lib/__tests__/idp-session.test.ts +22 -0
- package/src/lib/__tests__/idp.test.ts +36 -4
- package/src/lib/__tests__/instance-candidates.test.ts +1 -3
- package/src/lib/__tests__/instance-target.test.ts +7 -39
- package/src/lib/__tests__/instance.test.ts +6 -0
- package/src/lib/__tests__/log-errors.test.ts +64 -0
- package/src/lib/__tests__/studio-server-deps.test.ts +53 -16
- package/src/lib/__tests__/update.test.ts +113 -8
- package/src/lib/__tests__/view-open-intent.test.ts +0 -2
- package/src/lib/__tests__/view-server.test.ts +1 -1
- package/src/lib/__tests__/view-session.test.ts +1 -1
- package/src/lib/admin-instance.ts +14 -8
- package/src/lib/admin-target.ts +21 -2
- package/src/lib/command-dx.ts +9 -9
- package/src/lib/domain-publication.ts +104 -0
- package/src/lib/failure-debug.ts +26 -0
- package/src/lib/idp.ts +39 -4
- package/src/lib/instance-candidates.ts +2 -2
- package/src/lib/instance-target.ts +3 -14
- package/src/lib/instance.ts +22 -12
- package/src/lib/log.ts +16 -9
- package/src/lib/login-flow.ts +13 -3
- package/src/lib/meta.ts +2 -2
- package/src/lib/provision-instance.ts +34 -57
- package/src/lib/update.ts +124 -30
- package/src/lib/validation.ts +2 -2
- package/src/lib/view/resolve.ts +1 -1
- package/src/program/__tests__/program.test.ts +20 -4
- package/src/program/build.ts +2 -2
- package/src/setup/__tests__/instance-step.test.ts +27 -10
- package/src/setup/steps/instance.ts +22 -15
- package/studio/client/dist/assets/{elk-api-D2xgMJvi.js → elk-api-ByzoDZWH.js} +1 -1
- package/studio/client/dist/assets/index-B0RCgUOT.js +8 -0
- package/studio/client/dist/assets/index-BiGR8Oo9.css +1 -0
- package/studio/client/dist/assets/index-N8J8EKlB.js +81 -0
- package/studio/client/dist/index.html +2 -2
- package/studio/package.json +5 -10
- package/studio/server/agent/ask.test.ts +1 -1
- package/studio/server/agent/bridge/grant.test.ts +1 -1
- package/studio/server/agent/bridge/routes.test.ts +1 -1
- package/studio/server/agent/bridge/stdio.ts +8 -1
- package/studio/server/agent/conversation.test.ts +10 -5
- package/studio/server/agent/conversation.ts +56 -8
- package/studio/server/agent/harness/claude/adapter.test.ts +15 -5
- package/studio/server/agent/harness/codex/loadout.ts +18 -21
- package/studio/server/agent/harness/gateway/config.ts +20 -18
- package/studio/server/agent/harness/selection.ts +9 -1
- package/studio/server/agent/prompts/anchors.test.ts +32 -36
- package/studio/server/agent/prompts/anchors.ts +20 -49
- package/studio/server/agent/prompts/system.test.ts +3 -2
- package/studio/server/agent/prompts/system.ts +6 -5
- package/studio/server/agent/prompts/turn.ts +13 -4
- package/studio/server/agent/routes.test.ts +1 -1
- package/studio/server/agent/run/completion.ts +2 -2
- package/studio/server/agent/run/coordinator.test.ts +1 -1
- package/studio/server/agent/run/preparation.ts +6 -5
- package/studio/server/agent/run/transcript.test.ts +35 -1
- package/studio/server/agent/run/transcript.ts +169 -3
- package/studio/server/agent/run/usage.test.ts +24 -0
- package/studio/server/agent/run/usage.ts +26 -1
- package/studio/server/api/canvas.ts +43 -0
- package/studio/server/api/comments.ts +85 -0
- package/studio/server/api/context.ts +61 -0
- package/studio/server/api/deployment.ts +39 -0
- package/studio/server/api/documents.ts +55 -0
- package/studio/server/api/domain.ts +59 -0
- package/studio/server/api/http.ts +45 -0
- package/studio/server/api/project.ts +57 -0
- package/studio/server/api/schema.ts +12 -0
- package/studio/server/api/views.ts +57 -0
- package/studio/server/api/workspace.ts +60 -0
- package/studio/server/api-agent-loadout.test.ts +1 -1
- package/studio/server/api.test.ts +147 -0
- package/studio/server/api.ts +20 -422
- package/studio/server/cache.test.ts +122 -0
- package/studio/server/cache.ts +162 -11
- package/studio/server/cli-consumers.test.ts +494 -0
- package/studio/server/cli.test.ts +88 -0
- package/studio/server/cli.ts +240 -0
- package/studio/server/client-package.ts +25 -1
- package/studio/server/domain.test.ts +50 -40
- package/studio/server/domain.ts +83 -52
- package/studio/server/environment/dotenv-preview.test.ts +39 -0
- package/studio/server/environment/dotenv-preview.ts +27 -0
- package/studio/server/environment/files.test.ts +53 -0
- package/studio/server/{state/env.ts → environment/files.ts} +7 -48
- package/studio/server/{state → handoff}/copy.ts +21 -6
- package/studio/server/handoff/service.test.ts +22 -0
- package/studio/server/{state/handoff.ts → handoff/service.ts} +21 -14
- package/studio/server/index.ts +1 -1
- package/studio/server/instances/active.ts +72 -0
- package/studio/server/instances/deploy-record.test.ts +31 -0
- package/studio/server/instances/deploy-record.ts +37 -0
- package/studio/server/instances/deploy.ts +56 -0
- package/studio/server/{state/instance.test.ts → instances/probe.test.ts} +25 -21
- package/studio/server/instances/probe.ts +67 -0
- package/studio/server/instances/status.test.ts +12 -0
- package/studio/server/instances/status.ts +49 -0
- package/studio/server/introspect/anatomy/client-tree.ts +57 -0
- package/studio/server/introspect/anatomy/env-fields.ts +66 -0
- package/studio/server/introspect/anatomy/schema-definition.ts +53 -0
- package/studio/server/introspect/anatomy/source.ts +181 -0
- package/studio/server/introspect/anatomy/views/routes.ts +114 -0
- package/studio/server/introspect/anatomy/views.ts +53 -0
- package/studio/server/introspect/anatomy-extras.test.ts +106 -35
- package/studio/server/introspect/anatomy-extras.ts +7 -726
- package/studio/server/introspect/anatomy.test.ts +22 -14
- package/studio/server/introspect/anatomy.ts +52 -28
- package/studio/server/introspect/bundle.ts +15 -9
- package/studio/server/introspect/canonical-schema.test.ts +93 -309
- package/studio/server/introspect/canonical-schema.ts +257 -425
- package/studio/server/introspect/config-preview.test.ts +32 -0
- package/studio/server/introspect/config-preview.ts +119 -0
- package/studio/server/introspect/core-extractor.ts +18 -127
- package/studio/server/introspect/core.ts +1 -2
- package/studio/server/introspect/diff.test.ts +18 -18
- package/studio/server/introspect/diff.ts +44 -90
- package/studio/server/introspect/extractor.ts +23 -116
- package/studio/server/introspect/hash.ts +5 -2
- package/studio/server/introspect/overlay-tsmorph.test.ts +119 -240
- package/studio/server/introspect/overlay-tsmorph.ts +7 -1305
- package/studio/server/introspect/overlay.test.ts +26 -54
- package/studio/server/introspect/overlay.ts +10 -37
- package/studio/server/introspect/revision.test.ts +54 -0
- package/studio/server/introspect/revision.ts +49 -0
- package/studio/server/introspect/runtime.test.ts +83 -143
- package/studio/server/introspect/runtime.ts +40 -11
- package/studio/server/introspect/schema-ir-json.test.ts +70 -0
- package/studio/server/introspect/schema-ir-json.ts +151 -0
- package/studio/server/introspect/schema-refs.test.ts +43 -88
- package/studio/server/introspect/schema-refs.ts +14 -49
- package/studio/server/introspect/source-overlay/annotations.ts +14 -0
- package/studio/server/introspect/source-overlay/handlers.ts +161 -0
- package/studio/server/introspect/source-overlay/kernel-calls.ts +46 -0
- package/studio/server/introspect/source-overlay/project.ts +248 -0
- package/studio/server/introspect/source-overlay/spans.ts +330 -0
- package/studio/server/json.ts +46 -0
- package/studio/server/lifecycle.ts +5 -1
- package/studio/server/sse.test.ts +26 -0
- package/studio/server/sse.ts +4 -1
- package/studio/server/state/baseline.test.ts +223 -7
- package/studio/server/state/baseline.ts +148 -34
- package/studio/server/state/comments.test.ts +66 -1
- package/studio/server/state/comments.ts +173 -10
- package/studio/server/state/context.ts +34 -2
- package/studio/server/state/documents.ts +42 -1
- package/studio/server/state/integrations.ts +27 -1
- package/studio/server/state/layout.test.ts +34 -0
- package/studio/server/state/layout.ts +44 -17
- package/studio/server/state/settings.ts +29 -22
- package/studio/server/state/store.test.ts +122 -0
- package/studio/server/state/store.ts +66 -17
- package/studio/server/state/visibility.ts +22 -11
- package/studio/server/views/model.test.ts +57 -0
- package/studio/server/views/model.ts +66 -0
- package/studio/server/views/runtime.ts +40 -0
- package/studio/server/views/selection-repository.test.ts +31 -0
- package/studio/server/views/selection-repository.ts +60 -0
- package/studio/server/views/session.test.ts +73 -0
- package/studio/server/views/session.ts +166 -0
- package/studio/server/views/target.test.ts +78 -0
- package/studio/server/views/target.ts +222 -0
- package/studio/server/watch.test.ts +11 -11
- package/studio/server/watch.ts +9 -5
- package/studio/server/workspace/catalog.test.ts +17 -0
- package/studio/server/workspace/catalog.ts +43 -0
- package/studio/server/{state → workspace}/create.test.ts +1 -1
- package/studio/server/{state → workspace}/create.ts +1 -1
- package/studio/server/{state → workspace}/git.ts +1 -1
- package/studio/server/workspace/updates.ts +83 -0
- package/studio/server/workspace-state.ts +1 -1
- package/studio/server/workspace-watch.ts +2 -2
- package/studio/shared/contracts/README.md +16 -0
- package/studio/shared/contracts/agent.ts +270 -0
- package/studio/shared/contracts/runtime.ts +50 -0
- package/studio/shared/contracts/schema.ts +393 -0
- package/studio/shared/contracts/surface.test.ts +317 -0
- package/studio/shared/contracts/workspace.ts +265 -0
- package/studio/shared/layout.test.ts +116 -0
- package/studio/shared/schema/identity.test.ts +34 -0
- package/studio/shared/schema/identity.ts +68 -0
- package/studio/shared/types.ts +11 -1099
- package/studio/tsconfig.json +1 -1
- package/viewer/dist/main.js +40 -61
- package/.check-workspace.cjs +0 -40
- package/src/commands/__tests__/instance-create-hosts.test.ts +0 -29
- package/studio/client/dist/assets/index-BMdnsIJA.css +0 -1
- package/studio/client/dist/assets/index-D-vRV8w7.js +0 -8
- package/studio/client/dist/assets/index-LGSWRrk8.js +0 -81
- package/studio/server/state/catalog.ts +0 -117
- package/studio/server/state/instance.ts +0 -280
- package/studio/server/state/updates.ts +0 -63
- package/studio/server/state/views.test.ts +0 -286
- package/studio/server/state/views.ts +0 -535
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { afterEach, expect, test } from 'bun:test'
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
|
|
6
|
+
import { readEnvModel } from './files'
|
|
7
|
+
|
|
8
|
+
const roots: string[] = []
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('env editor composes typed fields with isolated config and dotenv previews', () => {
|
|
15
|
+
const root = mkdtempSync(join(tmpdir(), 'studio-env-preview-'))
|
|
16
|
+
roots.push(root)
|
|
17
|
+
writeFileSync(
|
|
18
|
+
join(root, 'env.ts'),
|
|
19
|
+
`export interface Env {
|
|
20
|
+
/** API credential. */
|
|
21
|
+
API_TOKEN: string
|
|
22
|
+
OPTIONAL_NOTE?: string
|
|
23
|
+
WORKER_URL: string
|
|
24
|
+
}`,
|
|
25
|
+
)
|
|
26
|
+
writeFileSync(
|
|
27
|
+
join(root, 'astrale.config.ts'),
|
|
28
|
+
`// astrale({ dev: { secrets: '.env.fake' } })
|
|
29
|
+
export default cloudflare({ dev: { secrets: '.env.dev' } })`,
|
|
30
|
+
)
|
|
31
|
+
writeFileSync(join(root, '.env.dev'), `BASE=token\nAPI_TOKEN="${'${BASE}'}-value"\nORPHAN=kept\n`)
|
|
32
|
+
|
|
33
|
+
expect(readEnvModel(root, 'dev')).toEqual({
|
|
34
|
+
env: 'dev',
|
|
35
|
+
file: '.env.dev',
|
|
36
|
+
configured: true,
|
|
37
|
+
exists: true,
|
|
38
|
+
adapter: 'cloudflare',
|
|
39
|
+
requiredMissing: 0,
|
|
40
|
+
rows: [
|
|
41
|
+
{
|
|
42
|
+
name: 'API_TOKEN',
|
|
43
|
+
value: 'token-value',
|
|
44
|
+
declared: true,
|
|
45
|
+
optional: false,
|
|
46
|
+
doc: 'API credential.',
|
|
47
|
+
},
|
|
48
|
+
{ name: 'OPTIONAL_NOTE', value: '', declared: true, optional: true },
|
|
49
|
+
{ name: 'BASE', value: 'token', declared: false, optional: true },
|
|
50
|
+
{ name: 'ORPHAN', value: 'kept', declared: false, optional: true },
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Environment file editor. Reconciles a domain's `.env.<env>` file
|
|
3
3
|
* (the actual secrets/vars, dotenv format) against the `Env` interface in
|
|
4
4
|
* `env.ts` (the typed contract, parsed by buildEnvFields), and is the ONE place
|
|
5
5
|
* the otherwise read-only studio writes a domain file — the explicit exception
|
|
@@ -16,6 +16,8 @@ import { join, resolve } from 'node:path'
|
|
|
16
16
|
import type { EnvFileModel, EnvName, EnvVarRow } from '../../shared/types'
|
|
17
17
|
|
|
18
18
|
import { buildEnvFields } from '../introspect/anatomy-extras'
|
|
19
|
+
import { readConfigPreview } from '../introspect/config-preview'
|
|
20
|
+
import { parseDotenvPreview } from './dotenv-preview'
|
|
19
21
|
|
|
20
22
|
const ENV_NAMES: EnvName[] = ['dev', 'prod']
|
|
21
23
|
export const isEnvName = (v: unknown): v is EnvName =>
|
|
@@ -25,55 +27,12 @@ export const isEnvName = (v: unknown): v is EnvName =>
|
|
|
25
27
|
* and every domain uses. The filename is fixed, so no path-traversal is possible. */
|
|
26
28
|
const envFileName = (env: EnvName) => `.env.${env}`
|
|
27
29
|
|
|
28
|
-
/** Mirror of the SDK's minimal dotenv parser (`@astrale-os/sdk` cli/dotenv) so the
|
|
29
|
-
* studio reads values exactly as the deploy path will: `#` comments, `export`,
|
|
30
|
-
* quotes (single = literal), `${VAR}` interpolation against earlier keys. */
|
|
31
|
-
function parseDotenv(contents: string): Record<string, string> {
|
|
32
|
-
const out: Record<string, string> = {}
|
|
33
|
-
for (const raw of contents.split('\n')) {
|
|
34
|
-
const line = raw.trim()
|
|
35
|
-
if (!line || line.startsWith('#')) continue
|
|
36
|
-
const m = /^(?:export\s+)?([A-Za-z_]\w*)\s*=\s*(.*)$/.exec(line)
|
|
37
|
-
if (!m) continue
|
|
38
|
-
let value = m[2].trim()
|
|
39
|
-
const single = value.length >= 2 && value.startsWith("'") && value.endsWith("'")
|
|
40
|
-
if (single || (value.length >= 2 && value.startsWith('"') && value.endsWith('"')))
|
|
41
|
-
value = value.slice(1, -1)
|
|
42
|
-
out[m[1]] = single ? value : value.replace(/\$\{(\w+)\}/g, (_, n: string) => out[n] ?? '')
|
|
43
|
-
}
|
|
44
|
-
return out
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** astrale.config.ts with comments stripped — so a COMMENTED-OUT adapter block
|
|
48
|
-
* (e.g. the scaffold's "swap to cloudflare" example) never reads as active config.
|
|
49
|
-
* The `[^:]` guard keeps `https://` in URLs from being mistaken for a line comment. */
|
|
50
|
-
function configText(root: string): string {
|
|
51
|
-
let s: string
|
|
52
|
-
try {
|
|
53
|
-
s = readFileSync(join(root, 'astrale.config.ts'), 'utf8')
|
|
54
|
-
} catch {
|
|
55
|
-
return ''
|
|
56
|
-
}
|
|
57
|
-
return s.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/.*$/gm, '$1')
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Is this `.env.<env>` wired into astrale.config's ACTIVE `secrets:`? (vs convention only) */
|
|
61
|
-
function isConfigured(config: string, env: EnvName): boolean {
|
|
62
|
-
return new RegExp(`secrets\\s*:\\s*['"]\\.env\\.${env}['"]`).test(config)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function adapterOf(config: string): EnvFileModel['adapter'] {
|
|
66
|
-
if (/\bastrale\s*\(/.test(config)) return 'astrale'
|
|
67
|
-
if (/\bcloudflare\s*\(/.test(config)) return 'cloudflare'
|
|
68
|
-
return 'unknown'
|
|
69
|
-
}
|
|
70
|
-
|
|
71
30
|
/** Build the merged model for one env: env.ts fillable fields ⨯ the `.env.<env>` values. */
|
|
72
31
|
export function readEnvModel(root: string, env: EnvName): EnvFileModel {
|
|
73
32
|
const file = envFileName(env)
|
|
74
33
|
const abs = join(root, file)
|
|
75
34
|
const exists = existsSync(abs)
|
|
76
|
-
const values = exists ?
|
|
35
|
+
const values = exists ? parseDotenvPreview(readFileSync(abs, 'utf8')) : {}
|
|
77
36
|
|
|
78
37
|
// env.ts contract — only fillable (non-binding) fields; bindings are adapter-injected.
|
|
79
38
|
const declared = buildEnvFields(root).filter((f) => f.secret)
|
|
@@ -92,13 +51,13 @@ export function readEnvModel(root: string, env: EnvName): EnvFileModel {
|
|
|
92
51
|
}
|
|
93
52
|
|
|
94
53
|
const requiredMissing = rows.filter((r) => r.declared && !r.optional && r.value === '').length
|
|
95
|
-
const config =
|
|
54
|
+
const config = readConfigPreview(root)
|
|
96
55
|
return {
|
|
97
56
|
env,
|
|
98
57
|
file,
|
|
99
|
-
configured:
|
|
58
|
+
configured: config.configuredSecretFiles.includes(file),
|
|
100
59
|
exists,
|
|
101
|
-
adapter:
|
|
60
|
+
adapter: config.adapter,
|
|
102
61
|
rows,
|
|
103
62
|
requiredMissing,
|
|
104
63
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Pure copy-payload projection for a Studio handoff (no IO). It turns studio
|
|
3
3
|
* state into a single Markdown handoff payload that an author agent can paste
|
|
4
4
|
* into its own session. The payload ends with a fenced ```json``` machine-state
|
|
5
5
|
* block in the annotate shape so the author can reply by appending
|
|
6
6
|
* {role:'author'} thread entries and merging back by id.
|
|
7
7
|
*/
|
|
8
|
-
import type { Comment, ContextItem, DocMeta, ThreadEntry } from '../../shared/types'
|
|
8
|
+
import type { Comment, ContextItem, DocMeta, SchemaRevision, ThreadEntry } from '../../shared/types'
|
|
9
9
|
|
|
10
10
|
interface CopyParts {
|
|
11
11
|
origin: string
|
|
12
12
|
root: string
|
|
13
|
-
|
|
13
|
+
/** Studio render fingerprint retained by the handoff machine-state. */
|
|
14
|
+
renderFingerprint: string
|
|
15
|
+
schemaRevision?: SchemaRevision
|
|
14
16
|
openComments: Comment[]
|
|
15
17
|
userContext: ContextItem[]
|
|
16
18
|
autoContext: ContextItem[]
|
|
@@ -61,7 +63,16 @@ function toMachineState(comment: Comment): {
|
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export function buildCopyMarkdown(parts: CopyParts): string {
|
|
64
|
-
const {
|
|
66
|
+
const {
|
|
67
|
+
origin,
|
|
68
|
+
root,
|
|
69
|
+
renderFingerprint,
|
|
70
|
+
schemaRevision,
|
|
71
|
+
openComments,
|
|
72
|
+
userContext,
|
|
73
|
+
autoContext,
|
|
74
|
+
documents = [],
|
|
75
|
+
} = parts
|
|
65
76
|
const lines: string[] = []
|
|
66
77
|
|
|
67
78
|
// ── Header ──
|
|
@@ -69,7 +80,8 @@ export function buildCopyMarkdown(parts: CopyParts): string {
|
|
|
69
80
|
lines.push('')
|
|
70
81
|
lines.push(`- **Origin:** \`${origin}\``)
|
|
71
82
|
lines.push(`- **Repo root:** \`${root}\``)
|
|
72
|
-
lines.push(`- **Schema
|
|
83
|
+
if (schemaRevision) lines.push(`- **Schema revision:** \`${schemaRevision}\``)
|
|
84
|
+
lines.push(`- **Render fingerprint:** \`${renderFingerprint}\``)
|
|
73
85
|
lines.push('')
|
|
74
86
|
lines.push(
|
|
75
87
|
'Load the **astrale-domain** skill, use the context/threads below, ' +
|
|
@@ -143,8 +155,11 @@ export function buildCopyMarkdown(parts: CopyParts): string {
|
|
|
143
155
|
}
|
|
144
156
|
|
|
145
157
|
// ── Trailing machine-state block ──
|
|
158
|
+
// `schemaVersion` is the established annotate wire key. Its value remains the
|
|
159
|
+
// render fingerprint because it detects anchor/layout drift, not installation
|
|
160
|
+
// compatibility.
|
|
146
161
|
const machineState = {
|
|
147
|
-
schemaVersion:
|
|
162
|
+
schemaVersion: renderFingerprint,
|
|
148
163
|
comments: openComments.map(toMachineState),
|
|
149
164
|
}
|
|
150
165
|
lines.push('```json')
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import type { ChangeSet } from '../../shared/types'
|
|
4
|
+
|
|
5
|
+
import { changeText } from './service'
|
|
6
|
+
|
|
7
|
+
test('labels schema changes as indicative structure rather than Runtime compatibility', () => {
|
|
8
|
+
const changes: ChangeSet = {
|
|
9
|
+
source: 'baseline',
|
|
10
|
+
hasGit: false,
|
|
11
|
+
hasBaseline: true,
|
|
12
|
+
schemaChanges: [{ kind: 'class-removed', target: 'Legacy' }],
|
|
13
|
+
fileChanges: [],
|
|
14
|
+
structuralStatus: 'changed',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const text = changeText(changes)
|
|
18
|
+
expect(text).toContain('Indicative source/structure diff only')
|
|
19
|
+
expect(text).toContain('~ class-removed Legacy')
|
|
20
|
+
expect(text).not.toContain('BREAKING')
|
|
21
|
+
expect(text).not.toContain('additive')
|
|
22
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Handoff service that turns live domain state into the "what changed
|
|
3
3
|
* + what to read" material both the Copy payload (api.ts) and the live agent
|
|
4
4
|
* runner depend on. Extracted so there is ONE definition of the change text and
|
|
5
5
|
* the auto-context refresh.
|
|
@@ -8,29 +8,36 @@ import type { ChangeSet } from '../../shared/types'
|
|
|
8
8
|
import type { DomainHandle } from '../domain'
|
|
9
9
|
|
|
10
10
|
import { getBundle } from '../cache'
|
|
11
|
-
import { computeChanges, hashAnatomyFiles } from '
|
|
12
|
-
import { readComments } from '
|
|
13
|
-
import { materializeAuto } from '
|
|
11
|
+
import { computeChanges, hashAnatomyFiles } from '../state/baseline'
|
|
12
|
+
import { readComments } from '../state/comments'
|
|
13
|
+
import { materializeAuto } from '../state/context'
|
|
14
|
+
import { detectGit, gitDiff } from '../workspace/git'
|
|
14
15
|
|
|
15
16
|
/** Current changes vs the review baseline (schema IR diff + anatomy file diff). */
|
|
16
17
|
export async function changeSet(handle: DomainHandle): Promise<ChangeSet> {
|
|
17
18
|
const bundle = await getBundle(handle.id)
|
|
18
19
|
const files = hashAnatomyFiles(handle.root, handle.schemaDirName)
|
|
20
|
+
const { hasGit } = detectGit(handle.root)
|
|
21
|
+
const diffText = hasGit ? gitDiff(handle.root, handle.schemaDirName) : null
|
|
19
22
|
return computeChanges(handle.root, bundle?.ir ?? null, files, {
|
|
20
|
-
|
|
23
|
+
currentRevision: bundle?.schemaRevision ?? null,
|
|
24
|
+
git: {
|
|
25
|
+
hasGit,
|
|
26
|
+
...(diffText === null ? {} : { diffText }),
|
|
27
|
+
},
|
|
21
28
|
})
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
/** A human-readable "current changes" blob for the handoff payload. */
|
|
25
32
|
export function changeText(cs: ChangeSet): string {
|
|
26
|
-
|
|
33
|
+
const notice =
|
|
34
|
+
'Indicative source/structure diff only; the Kernel Runtime has not assessed installation or data migration.'
|
|
35
|
+
if (cs.schemaDiffText && cs.schemaDiffText.trim()) return `${notice}\n${cs.schemaDiffText.trim()}`
|
|
27
36
|
const lines: string[] = []
|
|
28
37
|
for (const c of cs.schemaChanges)
|
|
29
|
-
lines.push(
|
|
30
|
-
`${c.breaking ? '! ' : '+ '}${c.kind} ${c.target}${c.detail ? ` (${c.detail})` : ''}`,
|
|
31
|
-
)
|
|
38
|
+
lines.push(`~ ${c.kind} ${c.target}${c.detail ? ` (${c.detail})` : ''}`)
|
|
32
39
|
for (const f of cs.fileChanges) lines.push(`~ ${f.status} ${f.file}`)
|
|
33
|
-
return lines.join('\n')
|
|
40
|
+
return lines.length > 0 ? `${notice}\n${lines.join('\n')}` : ''
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
/** Refresh the on-disk context/auto digests so an external agent can read them. */
|
|
@@ -44,12 +51,12 @@ export async function refreshAuto(handle: DomainHandle): Promise<void> {
|
|
|
44
51
|
`${i + 1}. [${c.kind} ${c.id}] ${c.anchorRefs[0]?.ref ?? ''} — ${c.thread.at(-1)?.text ?? ''}`,
|
|
45
52
|
)
|
|
46
53
|
.join('\n')
|
|
47
|
-
const schemaSummary = cs.schemaChanges
|
|
48
|
-
.map((c) => `${c.breaking ? 'BREAKING ' : ''}${c.kind} ${c.target}`)
|
|
49
|
-
.join('\n')
|
|
54
|
+
const schemaSummary = cs.schemaChanges.map((c) => `STRUCTURAL ${c.kind} ${c.target}`).join('\n')
|
|
50
55
|
materializeAuto(handle.root, {
|
|
51
56
|
changes: changeText(cs) || 'no tracked changes',
|
|
52
|
-
schemaChange: schemaSummary
|
|
57
|
+
schemaChange: schemaSummary
|
|
58
|
+
? `Indicative only; Runtime compatibility was not assessed.\n${schemaSummary}`
|
|
59
|
+
: 'no schema changes since baseline',
|
|
53
60
|
comments: commentsDigest || 'no open comments',
|
|
54
61
|
})
|
|
55
62
|
}
|
package/studio/server/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ const domains = resolveTarget(target, schemaDir)
|
|
|
42
42
|
if (!domains.length) {
|
|
43
43
|
console.error(`\n ✗ No Astrale domains found at ${target}`)
|
|
44
44
|
console.error(
|
|
45
|
-
` (looking for: astrale.config.ts +
|
|
45
|
+
` (looking for: astrale.config.ts + application.ts + schema.ts or ${schemaDir}/index.ts)\n`,
|
|
46
46
|
)
|
|
47
47
|
process.exit(1)
|
|
48
48
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { InstanceInfo, InstancesState } from '../../shared/types'
|
|
2
|
+
|
|
3
|
+
import { decodeJsonObject, runStudioCliJson, runStudioCliText } from '../cli'
|
|
4
|
+
|
|
5
|
+
async function astraleJson(args: string[]): Promise<Record<string, unknown> | null> {
|
|
6
|
+
const result = await runStudioCliJson(args, decodeJsonObject)
|
|
7
|
+
return result.ok ? result.data : null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function records(value: unknown): Record<string, unknown>[] {
|
|
11
|
+
return Array.isArray(value) ? value.map(decodeJsonObject).filter((item) => item !== null) : []
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function activeName(): Promise<string | null> {
|
|
15
|
+
const active = await astraleJson(['instance', 'active', '--json'])
|
|
16
|
+
return typeof active?.name === 'string' ? active.name : null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The CLI-owned global active instance. */
|
|
20
|
+
export const activeInstanceName = activeName
|
|
21
|
+
|
|
22
|
+
export async function listInstances(): Promise<InstancesState> {
|
|
23
|
+
const local = await astraleJson(['instance', 'list', '--bookmarked', '--json'])
|
|
24
|
+
const active = typeof local?.active === 'string' ? local.active : await activeName()
|
|
25
|
+
const instances: InstanceInfo[] = []
|
|
26
|
+
for (const bookmark of records(local?.bookmarks)) {
|
|
27
|
+
if (typeof bookmark.name !== 'string') continue
|
|
28
|
+
instances.push({
|
|
29
|
+
name: bookmark.name,
|
|
30
|
+
url: typeof bookmark.url === 'string' ? bookmark.url : '',
|
|
31
|
+
active: bookmark.active === true || bookmark.name === active,
|
|
32
|
+
kind: 'bookmark',
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
const managed = await astraleJson(['instance', 'list', '--admin-only', '--json'])
|
|
36
|
+
for (const item of records(managed?.instances)) {
|
|
37
|
+
if (
|
|
38
|
+
typeof item.slug !== 'string' ||
|
|
39
|
+
instances.some((instance) => instance.name === item.slug)
|
|
40
|
+
) {
|
|
41
|
+
continue
|
|
42
|
+
}
|
|
43
|
+
instances.push({
|
|
44
|
+
name: item.slug,
|
|
45
|
+
url: typeof item.url === 'string' ? item.url : '',
|
|
46
|
+
active: item.slug === active,
|
|
47
|
+
kind: 'managed',
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
if (active && !instances.some((instance) => instance.name === active)) {
|
|
51
|
+
instances.unshift({ name: active, url: '', active: true, kind: 'bookmark' })
|
|
52
|
+
}
|
|
53
|
+
return { active, instances }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function setActiveInstance(
|
|
57
|
+
name: string,
|
|
58
|
+
): Promise<{ ok: boolean; active: string | null; output: string }> {
|
|
59
|
+
const result = await runStudioCliText([
|
|
60
|
+
'instance',
|
|
61
|
+
'use',
|
|
62
|
+
name,
|
|
63
|
+
'--adopt-default',
|
|
64
|
+
'--skip-jwks-check',
|
|
65
|
+
])
|
|
66
|
+
const combined = `${result.stdout}\n${result.stderr}`.trim()
|
|
67
|
+
return {
|
|
68
|
+
ok: result.ok,
|
|
69
|
+
active: await activeName(),
|
|
70
|
+
output: (combined || result.detail).slice(-1000),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { afterEach, expect, test } from 'bun:test'
|
|
2
|
+
import { mkdtempSync, rmSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
|
|
6
|
+
import { writeJson } from '../state/store'
|
|
7
|
+
import { lastDeploy } from './deploy-record'
|
|
8
|
+
|
|
9
|
+
const roots: string[] = []
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
while (roots.length > 0) rmSync(roots.pop()!, { recursive: true, force: true })
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
test('reads the previous deploy fingerprint key but exposes only the current name', () => {
|
|
16
|
+
const root = mkdtempSync(join(tmpdir(), 'studio-deploy-record-'))
|
|
17
|
+
roots.push(root)
|
|
18
|
+
writeJson(root, 'deploy.json', {
|
|
19
|
+
at: '2026-08-20T00:00:00.000Z',
|
|
20
|
+
schemaHash: 'sha-legacy',
|
|
21
|
+
ok: true,
|
|
22
|
+
url: 'https://notes.svc.example.astrale.ai',
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
expect(lastDeploy(root)).toEqual({
|
|
26
|
+
at: '2026-08-20T00:00:00.000Z',
|
|
27
|
+
renderFingerprint: 'sha-legacy',
|
|
28
|
+
ok: true,
|
|
29
|
+
url: 'https://notes.svc.example.astrale.ai',
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DeployRecord } from '../../shared/types'
|
|
2
|
+
|
|
3
|
+
import { asJsonRecord, asString } from '../json'
|
|
4
|
+
import { readJson, writeJson } from '../state/store'
|
|
5
|
+
|
|
6
|
+
const DEPLOY_RECORD_FILE = 'deploy.json'
|
|
7
|
+
|
|
8
|
+
function decodeDeployRecord(value: unknown): DeployRecord | undefined {
|
|
9
|
+
const stored = asJsonRecord(value)
|
|
10
|
+
const at = asString(stored?.at)
|
|
11
|
+
if (!at || stored?.ok !== true) return undefined
|
|
12
|
+
const renderFingerprint = asString(stored.renderFingerprint) ?? asString(stored.schemaHash) ?? ''
|
|
13
|
+
const url = asString(stored.url)
|
|
14
|
+
return {
|
|
15
|
+
at,
|
|
16
|
+
renderFingerprint,
|
|
17
|
+
ok: true,
|
|
18
|
+
...(url === undefined ? {} : { url }),
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function lastDeploy(root: string): DeployRecord | null {
|
|
23
|
+
return readJson(root, DEPLOY_RECORD_FILE, decodeDeployRecord, null)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function recordSuccessfulDeploy(
|
|
27
|
+
root: string,
|
|
28
|
+
renderFingerprint: string | null,
|
|
29
|
+
url: string | null,
|
|
30
|
+
): void {
|
|
31
|
+
writeJson(root, DEPLOY_RECORD_FILE, {
|
|
32
|
+
at: new Date().toISOString(),
|
|
33
|
+
renderFingerprint: renderFingerprint ?? '',
|
|
34
|
+
ok: true,
|
|
35
|
+
url: url ?? undefined,
|
|
36
|
+
} satisfies DeployRecord)
|
|
37
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import type { DeployResult } from '../../shared/types'
|
|
5
|
+
import type { DomainHandle } from '../domain'
|
|
6
|
+
|
|
7
|
+
import { recordSuccessfulDeploy } from './deploy-record'
|
|
8
|
+
|
|
9
|
+
export function hasProdScript(root: string): boolean {
|
|
10
|
+
try {
|
|
11
|
+
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
|
12
|
+
return typeof pkg?.scripts?.prod === 'string'
|
|
13
|
+
} catch {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const SVC_URL = /https:\/\/[\w-]+\.svc\.[\w.-]+\.astrale\.ai\b/
|
|
19
|
+
|
|
20
|
+
/** Run `pnpm prod` only after an explicit outward-facing deploy request. */
|
|
21
|
+
export async function runDeploy(
|
|
22
|
+
handle: DomainHandle,
|
|
23
|
+
renderFingerprint: string | null,
|
|
24
|
+
): Promise<DeployResult> {
|
|
25
|
+
if (!hasProdScript(handle.root)) {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
url: null,
|
|
29
|
+
output:
|
|
30
|
+
'This domain has no "prod" script in package.json — it is not deployable via `pnpm prod`.',
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let out = ''
|
|
34
|
+
let err = ''
|
|
35
|
+
let code = 1
|
|
36
|
+
try {
|
|
37
|
+
const proc = Bun.spawn(['pnpm', 'prod'], {
|
|
38
|
+
cwd: handle.root,
|
|
39
|
+
stdout: 'pipe',
|
|
40
|
+
stderr: 'pipe',
|
|
41
|
+
})
|
|
42
|
+
;[out, err] = await Promise.all([
|
|
43
|
+
new Response(proc.stdout).text(),
|
|
44
|
+
new Response(proc.stderr).text(),
|
|
45
|
+
])
|
|
46
|
+
code = await proc.exited
|
|
47
|
+
} catch (error) {
|
|
48
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
49
|
+
return { ok: false, url: null, output: `failed to start pnpm: ${message}` }
|
|
50
|
+
}
|
|
51
|
+
const combined = `${out}\n${err}`.trim()
|
|
52
|
+
const url = combined.match(SVC_URL)?.[0] ?? null
|
|
53
|
+
const ok = code === 0
|
|
54
|
+
if (ok) recordSuccessfulDeploy(handle.root, renderFingerprint, url)
|
|
55
|
+
return { ok, url, output: combined.slice(-6000) }
|
|
56
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
installedBundleRootHash,
|
|
6
|
-
installedDomainCommand,
|
|
7
|
-
installedDomainProbeResult,
|
|
8
|
-
} from './instance'
|
|
3
|
+
import { installedDomainCommand, installedDomainProbeResult } from './probe'
|
|
9
4
|
|
|
10
5
|
describe('installed Domain introspection', () => {
|
|
11
6
|
test('uses the public bundle introspection command for the selected instance', () => {
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const descriptor = JSON.stringify({
|
|
8
|
+
version: 1,
|
|
9
|
+
executable: '/usr/local/bin/bun',
|
|
10
|
+
args: ['/workspace/cli/bin/astrale.ts'],
|
|
11
|
+
})
|
|
12
|
+
expect(installedDomainCommand('issues.astrale.ai', 'staging', descriptor)).toEqual([
|
|
13
|
+
'/usr/local/bin/bun',
|
|
14
|
+
'/workspace/cli/bin/astrale.ts',
|
|
14
15
|
'introspect',
|
|
15
16
|
'issues.astrale.ai',
|
|
16
17
|
'--bundle',
|
|
@@ -20,22 +21,25 @@ describe('installed Domain introspection', () => {
|
|
|
20
21
|
])
|
|
21
22
|
})
|
|
22
23
|
|
|
23
|
-
test('
|
|
24
|
+
test('retains the complete installed Bundle for installed SDK admission', () => {
|
|
24
25
|
const root = {
|
|
25
26
|
version: 'v1',
|
|
26
27
|
domain: 'issues.astrale.ai',
|
|
27
28
|
classes: { Issue: { properties: { title: { type: 'string' } } } },
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
expect(
|
|
31
|
+
installedDomainProbeResult(
|
|
32
|
+
JSON.stringify({
|
|
33
|
+
state: 'ready',
|
|
34
|
+
bundle: { format: 'astrale.dsl.bundle', version: 'v1', root, closure: [] },
|
|
35
|
+
}),
|
|
36
|
+
'',
|
|
37
|
+
0,
|
|
38
|
+
),
|
|
39
|
+
).toEqual({
|
|
40
|
+
state: 'installed',
|
|
41
|
+
bundle: { format: 'astrale.dsl.bundle', version: 'v1', root, closure: [] },
|
|
42
|
+
})
|
|
39
43
|
})
|
|
40
44
|
|
|
41
45
|
test('does not mistake the removed Domain Node shape for installation introspection', () => {
|
|
@@ -45,7 +49,7 @@ describe('installed Domain introspection', () => {
|
|
|
45
49
|
'',
|
|
46
50
|
0,
|
|
47
51
|
),
|
|
48
|
-
).toEqual({ state: 'unknown',
|
|
52
|
+
).toEqual({ state: 'unknown', bundle: null })
|
|
49
53
|
})
|
|
50
54
|
|
|
51
55
|
test('recognizes the current CLI not-installed diagnostic', () => {
|
|
@@ -58,6 +62,6 @@ describe('installed Domain introspection', () => {
|
|
|
58
62
|
}),
|
|
59
63
|
1,
|
|
60
64
|
),
|
|
61
|
-
).toEqual({ state: 'not-installed',
|
|
65
|
+
).toEqual({ state: 'not-installed', bundle: null })
|
|
62
66
|
})
|
|
63
67
|
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { decodeJsonObject, runStudioCliJson, studioCliCommand } from '../cli'
|
|
2
|
+
|
|
3
|
+
function installedDomainArgs(origin: string, instance: string): string[] {
|
|
4
|
+
return ['introspect', origin, '--bundle', '--json', '-i', instance]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function installedDomainCommand(
|
|
8
|
+
origin: string,
|
|
9
|
+
instance: string,
|
|
10
|
+
encodedDescriptor?: string,
|
|
11
|
+
): string[] {
|
|
12
|
+
return studioCliCommand(installedDomainArgs(origin, instance), encodedDescriptor)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type InstalledDomainProbe =
|
|
16
|
+
| { state: 'installed'; bundle: unknown }
|
|
17
|
+
| { state: 'not-installed' | 'unknown'; bundle: null }
|
|
18
|
+
|
|
19
|
+
function jsonObject(text: string): Record<string, unknown> | null {
|
|
20
|
+
try {
|
|
21
|
+
const value = JSON.parse(text)
|
|
22
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null
|
|
23
|
+
} catch {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function installedDomainProbeResult(
|
|
29
|
+
stdout: string,
|
|
30
|
+
stderr: string,
|
|
31
|
+
exitCode: number,
|
|
32
|
+
): InstalledDomainProbe {
|
|
33
|
+
const output = jsonObject(stdout)
|
|
34
|
+
const diagnostic = jsonObject(stderr)
|
|
35
|
+
const error = output?.error ?? diagnostic?.error
|
|
36
|
+
if (
|
|
37
|
+
error === 'DOMAIN_NOT_INSTALLED' ||
|
|
38
|
+
error === 'NOT_FOUND' ||
|
|
39
|
+
/\b(?:DOMAIN_NOT_INSTALLED|NOT_FOUND)\b/.test(`${stdout}\n${stderr}`)
|
|
40
|
+
) {
|
|
41
|
+
return { state: 'not-installed', bundle: null }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (exitCode === 0) {
|
|
45
|
+
const bundle = output?.bundle
|
|
46
|
+
if (
|
|
47
|
+
bundle !== null &&
|
|
48
|
+
typeof bundle === 'object' &&
|
|
49
|
+
!Array.isArray(bundle) &&
|
|
50
|
+
Object.prototype.hasOwnProperty.call(bundle, 'root')
|
|
51
|
+
) {
|
|
52
|
+
return { state: 'installed', bundle }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { state: 'unknown', bundle: null }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function getInstalledDomain(
|
|
59
|
+
origin: string,
|
|
60
|
+
instance: string,
|
|
61
|
+
timeoutMs = 8000,
|
|
62
|
+
): Promise<InstalledDomainProbe> {
|
|
63
|
+
const result = await runStudioCliJson(installedDomainArgs(origin, instance), decodeJsonObject, {
|
|
64
|
+
timeoutMs,
|
|
65
|
+
})
|
|
66
|
+
return installedDomainProbeResult(result.stdout, result.stderr, result.exitCode)
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { schemaRevisionDrift } from './status'
|
|
4
|
+
|
|
5
|
+
test('computes drift only from two admitted canonical revisions', () => {
|
|
6
|
+
const local = `sha256:${'a'.repeat(64)}` as const
|
|
7
|
+
const other = `sha256:${'b'.repeat(64)}` as const
|
|
8
|
+
expect(schemaRevisionDrift(local, local)).toBe('in-sync')
|
|
9
|
+
expect(schemaRevisionDrift(local, other)).toBe('drifted')
|
|
10
|
+
expect(schemaRevisionDrift(local, null)).toBe('unknown')
|
|
11
|
+
expect(schemaRevisionDrift(null, other)).toBe('unknown')
|
|
12
|
+
})
|