@astrale-os/cli 1.0.0-beta.4 → 1.0.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.
- package/dist/astrale.js +55649 -59388
- package/dist/public/connect-core.js +1972 -26831
- package/dist/public/keys/index.js +1754 -40686
- package/dist/public/paths/index.js +859 -39511
- package/dist/types/admin/instance/model.d.ts +3 -4
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/lib/idp.d.ts +1 -0
- package/dist/types/lib/instance-target.d.ts +1 -1
- package/dist/types/lib/log.d.ts +2 -2
- package/dist/types/lib/update.d.ts +30 -0
- package/package.json +4 -6
- package/src/__tests__/fixtures/publication.ts +20 -0
- package/src/admin/__tests__/binding.test.ts +14 -21
- package/src/admin/__tests__/fixture.ts +101 -0
- package/src/admin/binding.ts +86 -6
- 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 +35 -26
- 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 +58 -83
- package/src/admin/instance/client.ts +49 -39
- package/src/admin/instance/model.ts +9 -8
- package/src/commands/__tests__/call-describe.test.ts +46 -33
- package/src/commands/__tests__/domain-install-operation.test.ts +3 -14
- package/src/commands/__tests__/domain-install-owned.test.ts +1 -1
- package/src/commands/__tests__/domain-list.test.ts +5 -25
- package/src/commands/__tests__/install-identity-override.test.ts +3 -14
- package/src/commands/__tests__/read-commands.test.ts +35 -10
- package/src/commands/__tests__/update.test.ts +25 -3
- package/src/commands/call-describe.ts +59 -67
- package/src/commands/call.ts +41 -54
- package/src/commands/domain/install.ts +2 -2
- package/src/commands/domain/uninstall.ts +2 -2
- package/src/commands/get.ts +13 -14
- package/src/commands/identity/__tests__/register.test.ts +3 -3
- package/src/commands/identity/register.ts +5 -4
- package/src/commands/instance/delete.ts +5 -3
- package/src/commands/instance/status.ts +1 -9
- package/src/commands/introspect.ts +4 -11
- package/src/commands/logs.ts +24 -25
- package/src/commands/mutate.ts +6 -5
- package/src/commands/query.ts +27 -30
- package/src/commands/token.ts +8 -7
- package/src/commands/update.ts +31 -11
- package/src/commands/view.ts +4 -3
- 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 +1 -1
- package/src/connection/__tests__/errors.test.ts +27 -20
- package/src/connection/__tests__/exchange.test.ts +30 -1
- 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/call.ts +1 -1
- package/src/connection/credential.ts +2 -2
- package/src/connection/errors.ts +1 -355
- package/src/connection/exchange.ts +47 -23
- package/src/connection/failure/classify.ts +110 -0
- package/src/connection/failure/debug.ts +26 -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 +8 -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/lib/__tests__/domain-publication.test.ts +4 -15
- package/src/lib/__tests__/idp.test.ts +25 -0
- package/src/lib/__tests__/instance-target.test.ts +6 -39
- package/src/lib/__tests__/log-errors.test.ts +53 -0
- package/src/lib/__tests__/studio-server-deps.test.ts +1 -1
- package/src/lib/__tests__/update.test.ts +101 -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/command-dx.ts +1 -4
- package/src/lib/domain-publication.ts +1 -1
- package/src/lib/idp.ts +29 -1
- package/src/lib/instance-target.ts +3 -14
- package/src/lib/log.ts +11 -6
- package/src/lib/update.ts +120 -26
- package/src/lib/validation.ts +2 -2
- package/src/lib/view/resolve.ts +1 -1
- package/src/program/__tests__/program.test.ts +1 -1
- package/studio/client/dist/assets/{elk-api-lwhFo7vB.js → elk-api-Di4OXGNH.js} +1 -1
- package/studio/client/dist/assets/index-BLm6J11H.js +81 -0
- package/studio/client/dist/assets/index-BiGR8Oo9.css +1 -0
- package/studio/client/dist/assets/index-DTjvkOUX.js +8 -0
- package/studio/client/dist/index.html +2 -2
- package/studio/package.json +2 -9
- 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/harness/claude/adapter.test.ts +15 -5
- 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 +3 -3
- package/studio/server/agent/routes.test.ts +1 -1
- package/studio/server/agent/run/coordinator.test.ts +1 -1
- package/studio/server/api/canvas.ts +0 -1
- package/studio/server/api-agent-loadout.test.ts +1 -1
- package/studio/server/api.test.ts +1 -1
- package/studio/server/cache.test.ts +23 -12
- package/studio/server/cache.ts +12 -15
- package/studio/server/domain.test.ts +50 -68
- package/studio/server/domain.ts +82 -63
- package/studio/server/handoff/copy.ts +1 -1
- package/studio/server/index.ts +1 -1
- package/studio/server/instances/probe.test.ts +1 -1
- package/studio/server/introspect/anatomy/views/routes.ts +46 -37
- package/studio/server/introspect/anatomy/views.ts +9 -14
- package/studio/server/introspect/anatomy-extras.test.ts +26 -42
- package/studio/server/introspect/anatomy.test.ts +22 -14
- package/studio/server/introspect/anatomy.ts +6 -9
- package/studio/server/introspect/bundle.ts +0 -3
- package/studio/server/introspect/canonical-schema.test.ts +94 -389
- package/studio/server/introspect/canonical-schema.ts +227 -457
- package/studio/server/introspect/core-extractor.ts +18 -127
- package/studio/server/introspect/core.ts +1 -2
- package/studio/server/introspect/diff.test.ts +11 -7
- package/studio/server/introspect/diff.ts +18 -55
- package/studio/server/introspect/extractor.ts +22 -117
- package/studio/server/introspect/overlay-tsmorph.test.ts +119 -240
- package/studio/server/introspect/overlay.test.ts +26 -54
- package/studio/server/introspect/overlay.ts +10 -37
- package/studio/server/introspect/revision.test.ts +1 -1
- package/studio/server/introspect/revision.ts +1 -1
- package/studio/server/introspect/runtime.test.ts +65 -183
- package/studio/server/introspect/runtime.ts +8 -25
- package/studio/server/introspect/schema-ir-json.test.ts +70 -0
- package/studio/server/introspect/schema-ir-json.ts +38 -68
- 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/handlers.ts +116 -636
- package/studio/server/introspect/source-overlay/kernel-calls.ts +0 -3
- package/studio/server/introspect/source-overlay/spans.ts +15 -45
- package/studio/server/state/baseline.test.ts +14 -9
- package/studio/server/state/baseline.ts +3 -5
- package/studio/server/state/visibility.ts +1 -5
- package/studio/server/views/model.ts +3 -3
- package/studio/server/views/target.test.ts +17 -74
- package/studio/server/views/target.ts +24 -50
- package/studio/server/watch.test.ts +11 -11
- package/studio/server/watch.ts +8 -4
- package/studio/server/workspace-watch.ts +2 -2
- package/studio/shared/contracts/schema.ts +38 -107
- package/studio/shared/contracts/surface.test.ts +13 -15
- package/studio/shared/contracts/workspace.ts +2 -11
- package/studio/shared/schema/identity.test.ts +20 -44
- package/studio/shared/schema/identity.ts +9 -23
- package/viewer/dist/main.js +40 -61
- package/studio/client/dist/assets/index-B-c-smo9.js +0 -8
- package/studio/client/dist/assets/index-BckHuAWk.js +0 -81
- package/studio/client/dist/assets/index-C4aNQ6dz.css +0 -1
- package/studio/server/introspect/anatomy/views/legacy.ts +0 -232
package/src/commands/update.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type SdkOutdated,
|
|
13
13
|
} from '../lib/sdk-deps'
|
|
14
14
|
import { ASTRALE_CLI_SKILL, detectSkill, installSkills, SKILL_INSTALL_HINT } from '../lib/skills'
|
|
15
|
-
import { DEFAULT_UPDATE_CHANNEL, updateAstrale } from '../lib/update'
|
|
15
|
+
import { DEFAULT_UPDATE_CHANNEL, packageManagedUpdateError, updateAstrale } from '../lib/update'
|
|
16
16
|
|
|
17
17
|
type UpdateOpts = RawOutputOpts & {
|
|
18
18
|
check?: boolean
|
|
@@ -104,14 +104,22 @@ async function refreshSdkDeps(check: boolean, assumeYes = false): Promise<boolea
|
|
|
104
104
|
/**
|
|
105
105
|
* Read-only staleness report for tooling — `astrale update --check --json`.
|
|
106
106
|
* domain-studio polls this on load to drive its "update available" badge. It is
|
|
107
|
-
* unified and NON-THROWING:
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* update`, so a stale CLI or
|
|
107
|
+
* unified and NON-THROWING: an explicit package-managed result uses npm release
|
|
108
|
+
* identity, while script-install failures remain script failures in `error`
|
|
109
|
+
* instead of being recategorized. The SDK axis is already best-effort. Skills are
|
|
110
|
+
* intentionally absent — they ride along with `astrale update`, so a stale CLI or
|
|
111
|
+
* SDK is the only signal worth surfacing.
|
|
111
112
|
*/
|
|
112
113
|
export type StaleReport = {
|
|
113
114
|
stale: boolean
|
|
114
|
-
cli: {
|
|
115
|
+
cli: {
|
|
116
|
+
stale: boolean
|
|
117
|
+
managed: boolean
|
|
118
|
+
current?: string
|
|
119
|
+
latest?: string
|
|
120
|
+
channel?: string
|
|
121
|
+
error?: string
|
|
122
|
+
}
|
|
115
123
|
sdk: { stale: boolean; inProject: boolean; outdated: SdkOutdated[] }
|
|
116
124
|
}
|
|
117
125
|
|
|
@@ -138,6 +146,15 @@ export async function cliStale(
|
|
|
138
146
|
version: target.version,
|
|
139
147
|
currentVersion: running,
|
|
140
148
|
})
|
|
149
|
+
if (r.status === 'managed') {
|
|
150
|
+
const latest = await dependencies.fetchPackageVersion(target).catch(() => undefined)
|
|
151
|
+
return {
|
|
152
|
+
stale: latest !== undefined && latest !== running,
|
|
153
|
+
managed: true,
|
|
154
|
+
current: running,
|
|
155
|
+
...(latest === undefined ? {} : { latest, channel: 'npm' }),
|
|
156
|
+
}
|
|
157
|
+
}
|
|
141
158
|
if (r.status === 'updated') {
|
|
142
159
|
return {
|
|
143
160
|
stale: false,
|
|
@@ -154,13 +171,12 @@ export async function cliStale(
|
|
|
154
171
|
latest: r.latestVersion,
|
|
155
172
|
channel: r.channel,
|
|
156
173
|
}
|
|
157
|
-
} catch {
|
|
158
|
-
const latest = await dependencies.fetchPackageVersion(target).catch(() => undefined)
|
|
174
|
+
} catch (error) {
|
|
159
175
|
return {
|
|
160
|
-
stale:
|
|
161
|
-
managed:
|
|
176
|
+
stale: false,
|
|
177
|
+
managed: false,
|
|
162
178
|
current: running,
|
|
163
|
-
|
|
179
|
+
error: error instanceof Error ? error.message : String(error),
|
|
164
180
|
}
|
|
165
181
|
}
|
|
166
182
|
}
|
|
@@ -294,6 +310,10 @@ Examples:
|
|
|
294
310
|
log.success(`Updated astrale ${result.previousVersion} -> ${result.currentVersion}`)
|
|
295
311
|
log.dim(` channel: ${result.channel}`)
|
|
296
312
|
log.dim(` binary: ${result.bin}`)
|
|
313
|
+
} else if (result?.status === 'managed') {
|
|
314
|
+
const error = packageManagedUpdateError(result.executable)
|
|
315
|
+
if (!opts.yes) throw error
|
|
316
|
+
log.warn(`CLI self-update skipped: ${error.message}`)
|
|
297
317
|
}
|
|
298
318
|
|
|
299
319
|
// Axis B — agent skills. Keep an existing install current with the CLI.
|
package/src/commands/view.ts
CHANGED
|
@@ -89,9 +89,10 @@ export async function resolveSession(
|
|
|
89
89
|
}
|
|
90
90
|
const targetInput =
|
|
91
91
|
parsed.kind === 'target' ? parsed.path : (opts.target ?? viewOwnerTarget(parsed.path))
|
|
92
|
-
const {
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const { target, candidates } = await withClientSession(opts, async (context) => {
|
|
93
|
+
const { path: target } = await expandSelfInPath(targetInput, context)
|
|
94
|
+
return { target, candidates: await resolveViewCandidates(context, target) }
|
|
95
|
+
})
|
|
95
96
|
|
|
96
97
|
if (opts.list) {
|
|
97
98
|
return { candidates }
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { Call } from '@astrale-os/kernel-client'
|
|
2
|
-
import type { AuthApi } from '@astrale-os/kernel-client/auth'
|
|
3
|
-
import type { GraphApi } from '@astrale-os/kernel-client/graph'
|
|
4
|
-
import type { ClientSession } from '@astrale-os/kernel-client/session'
|
|
5
1
|
import type { IssuerId } from '@astrale-os/sdk/auth'
|
|
2
|
+
import type { AuthApi } from '@astrale-os/sdk/auth'
|
|
3
|
+
import type { Call, GraphApi } from '@astrale-os/sdk/client'
|
|
4
|
+
import type { ClientSession } from '@astrale-os/sdk/client/session'
|
|
6
5
|
|
|
7
6
|
/** Existing CLI connection flags accepted by Kernel-touching commands. */
|
|
8
7
|
export interface ConnectionOptions {
|
|
@@ -78,17 +77,17 @@ export function withAdminClientSession<Value>(
|
|
|
78
77
|
/** Expand @self through the effective principal returned by authenticated Identity.whoami. */
|
|
79
78
|
export function expandSelfInPath(
|
|
80
79
|
path: string,
|
|
81
|
-
|
|
80
|
+
context: ConnectionContext,
|
|
82
81
|
): Promise<{ readonly path: string; readonly meta?: SelfExpansionMeta }>
|
|
83
82
|
|
|
84
83
|
/** Expand @self once across one Call path and its CLI-authored string parameters. */
|
|
85
84
|
export function expandSelfInCall(
|
|
86
85
|
path: string,
|
|
87
|
-
parameters:
|
|
88
|
-
|
|
86
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
87
|
+
context: ConnectionContext,
|
|
89
88
|
): Promise<{
|
|
90
89
|
readonly path: string
|
|
91
|
-
readonly parameters:
|
|
90
|
+
readonly parameters: Readonly<Record<string, unknown>>
|
|
92
91
|
readonly meta?: SelfExpansionMeta
|
|
93
92
|
}>
|
|
94
93
|
|
|
@@ -40,7 +40,8 @@ customizes only the Fetch capability passed to Client. `withClientSession` and
|
|
|
40
40
|
`withAdminClientSession` are terminal lifecycle boundaries: success, failure, and cancellation all
|
|
41
41
|
close both the Client Session and its direct source-Auth client.
|
|
42
42
|
|
|
43
|
-
The command boundary
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
The command boundary projects typed Client failure identity, transport context, phase, and
|
|
44
|
+
invocation-only delivery evidence without inspecting a private cause message. Unknown native
|
|
45
|
+
failures become one honest unexpected diagnostic; their bounded cause graph is visible only under
|
|
46
|
+
explicit debug output. Every admitted Kernel reason remains available in machine output, while
|
|
47
|
+
human repair details require a bounded public Function issue or exact Query reason variant.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Call } from '@astrale-os/sdk/client'
|
|
2
|
+
import type { SessionAuth } from '@astrale-os/sdk/client/session'
|
|
3
3
|
|
|
4
4
|
import type { ConnectionContext, ConnectionOptions, ConnectionTarget } from '../api.js'
|
|
5
5
|
|
|
@@ -111,7 +111,7 @@ export const CLI_AUTH_REGISTRATION_TARGET = defineLaw({
|
|
|
111
111
|
export const CLI_SELF_AUTHENTICATED_PRINCIPAL = defineLaw({
|
|
112
112
|
id: 'CLI-SELF-AUTHENTICATED-PRINCIPAL',
|
|
113
113
|
statement:
|
|
114
|
-
'@self resolves
|
|
114
|
+
'@self resolves inside the command-owned Client Session from authenticated Identity.whoami on the selected target, so resolution and dispatch share one lifecycle and delegated carriers never use an unverified JWT subject or stale local registration.',
|
|
115
115
|
tests: [
|
|
116
116
|
{
|
|
117
117
|
file: '__tests__/self.test.ts',
|
|
@@ -183,7 +183,7 @@ export const CLI_CONNECTION_PUBLIC_SEMANTIC_REASON = defineLaw({
|
|
|
183
183
|
export const CLI_CONNECTION_TYPED_ERROR_PRESENTATION = defineLaw({
|
|
184
184
|
id: 'CLI-CONNECTION-TYPED-ERROR-PRESENTATION',
|
|
185
185
|
statement:
|
|
186
|
-
'The command boundary maps typed Client transport phase and delivery evidence without parsing a private cause
|
|
186
|
+
'The command boundary maps typed Client failure identity, transport context, phase, and invocation-only delivery evidence without parsing a private cause; acquisition never receives retry advice, unknown native failures have one non-blank unexpected diagnostic, and raw causes appear only under explicit debug output.',
|
|
187
187
|
tests: [
|
|
188
188
|
{
|
|
189
189
|
file: '__tests__/errors.test.ts',
|
|
@@ -197,5 +197,9 @@ export const CLI_CONNECTION_TYPED_ERROR_PRESENTATION = defineLaw({
|
|
|
197
197
|
file: '__tests__/reasons.test.ts',
|
|
198
198
|
id: 'TEST-CLI-CONNECTION-ADMITS-BOUNDED-REASONS',
|
|
199
199
|
},
|
|
200
|
+
{
|
|
201
|
+
file: '__tests__/failure-safety.test.ts',
|
|
202
|
+
id: 'TEST-CLI-CONNECTION-FAILURE-SAFETY',
|
|
203
|
+
},
|
|
200
204
|
],
|
|
201
205
|
})
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ResponseError
|
|
1
|
+
import { ResponseError } from '@astrale-os/sdk/client'
|
|
2
|
+
import { Path } from '@astrale-os/sdk/graph/path'
|
|
2
3
|
import { describe, expect, test } from 'bun:test'
|
|
3
4
|
|
|
4
5
|
import { formatKernelError, functionInputIssues, schemaUpgradeHint } from '../errors'
|
|
6
|
+
import { transportFailure } from './failure-fixtures'
|
|
5
7
|
|
|
6
8
|
const CONFLICT = 4001
|
|
7
9
|
const VALIDATION = 1003
|
|
@@ -19,24 +21,28 @@ describe('formatKernelError', () => {
|
|
|
19
21
|
writes.push(typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk))
|
|
20
22
|
return true
|
|
21
23
|
}) as typeof process.stderr.write
|
|
22
|
-
const error =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const error = Object.assign(
|
|
25
|
+
transportFailure('Publication discovery request failed.', 'unknown', {
|
|
26
|
+
kind: 'acquisition',
|
|
27
|
+
resource: 'publication',
|
|
28
|
+
}),
|
|
29
|
+
{
|
|
30
|
+
url: 'https://localhost:8443/kernel/host',
|
|
31
|
+
cause: Object.assign(new Error('connect ECONNREFUSED'), { code: 'ECONNREFUSED' }),
|
|
32
|
+
},
|
|
33
|
+
)
|
|
28
34
|
try {
|
|
29
|
-
await formatKernelError(error, true)
|
|
35
|
+
await formatKernelError(error, true, 'https://localhost:8443/kernel/host')
|
|
30
36
|
} finally {
|
|
31
37
|
process.stderr.write = original
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
expect(JSON.parse(writes[0]!)).toMatchObject({
|
|
35
|
-
error: '
|
|
41
|
+
error: 'TRANSPORT_ERROR',
|
|
36
42
|
message: 'Publication discovery request failed.',
|
|
37
43
|
url: 'https://localhost:8443/kernel/host',
|
|
38
|
-
phase: '
|
|
39
|
-
|
|
44
|
+
phase: 'unknown',
|
|
45
|
+
transport: { kind: 'acquisition', resource: 'publication' },
|
|
40
46
|
})
|
|
41
47
|
expect(writes[0]).not.toContain('ECONNREFUSED')
|
|
42
48
|
})
|
|
@@ -50,9 +56,8 @@ describe('formatKernelError', () => {
|
|
|
50
56
|
}) as typeof process.stderr.write
|
|
51
57
|
try {
|
|
52
58
|
await formatKernelError(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
phase: 'timeout',
|
|
59
|
+
transportFailure('Request timed out.', 'timeout', {
|
|
60
|
+
kind: 'invocation',
|
|
56
61
|
delivery: 'unknown',
|
|
57
62
|
}),
|
|
58
63
|
true,
|
|
@@ -74,7 +79,7 @@ describe('formatKernelError', () => {
|
|
|
74
79
|
expect(JSON.parse(writes[0]!)).toMatchObject({
|
|
75
80
|
error: 'TIMEOUT',
|
|
76
81
|
phase: 'timeout',
|
|
77
|
-
delivery: 'unknown',
|
|
82
|
+
transport: { kind: 'invocation', delivery: 'unknown' },
|
|
78
83
|
operation: '4a4c9a18-50f6-4d84-a7b7-2d83e3e45dc8',
|
|
79
84
|
retry:
|
|
80
85
|
'astrale domain install https://crm.test --direct --operation 4a4c9a18-50f6-4d84-a7b7-2d83e3e45dc8',
|
|
@@ -229,7 +234,7 @@ describe('formatKernelError', () => {
|
|
|
229
234
|
)
|
|
230
235
|
})
|
|
231
236
|
|
|
232
|
-
test('maps SDK
|
|
237
|
+
test('maps SDK error identities to stable CLI error codes', async () => {
|
|
233
238
|
const writes: string[] = []
|
|
234
239
|
const original = process.stderr.write
|
|
235
240
|
process.stderr.write = ((chunk: string | Uint8Array) => {
|
|
@@ -237,15 +242,17 @@ describe('formatKernelError', () => {
|
|
|
237
242
|
return true
|
|
238
243
|
}) as typeof process.stderr.write
|
|
239
244
|
try {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
245
|
+
try {
|
|
246
|
+
Path.parse('not-a-path')
|
|
247
|
+
} catch (error) {
|
|
248
|
+
await formatKernelError(error, true)
|
|
249
|
+
}
|
|
243
250
|
} finally {
|
|
244
251
|
process.stderr.write = original
|
|
245
252
|
}
|
|
246
253
|
expect(JSON.parse(writes[0]!)).toEqual({
|
|
247
254
|
error: 'PATH_INVALID',
|
|
248
|
-
message:
|
|
255
|
+
message: expect.any(String),
|
|
249
256
|
})
|
|
250
257
|
})
|
|
251
258
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fetch } from '@astrale-os/
|
|
1
|
+
import type { Fetch } from '@astrale-os/sdk/client'
|
|
2
2
|
|
|
3
3
|
import { issuer } from '@astrale-os/sdk/auth'
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
@@ -190,6 +190,35 @@ describe('Domain token exchange', () => {
|
|
|
190
190
|
message: 'Token exchange returned an invalid success response.',
|
|
191
191
|
})
|
|
192
192
|
})
|
|
193
|
+
|
|
194
|
+
test('normalizes native issuer Fetch failures without exposing their message', async () => {
|
|
195
|
+
const native = new AggregateError([new Error('private DNS state')], '')
|
|
196
|
+
const resolver = createExchangeCredentialResolver(
|
|
197
|
+
TARGET,
|
|
198
|
+
{ resolve: async () => SOURCE_TOKEN },
|
|
199
|
+
async (input, init) => {
|
|
200
|
+
if (String(input) === INVOCATION) {
|
|
201
|
+
const body = JSON.parse(await new Response(init?.body).text()) as Record<string, any>
|
|
202
|
+
return invocationResponse(
|
|
203
|
+
body.requestId,
|
|
204
|
+
body.call.input && Object.keys(body.call.input).length === 0
|
|
205
|
+
? { id: 'user-1' }
|
|
206
|
+
: 'kernel-destination-envelope',
|
|
207
|
+
new Headers(init?.headers).get('accept')!,
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
throw native
|
|
211
|
+
},
|
|
212
|
+
5_000,
|
|
213
|
+
new ExchangeCredentialCache(join(directory, 'native-failure.json')),
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
await expect(resolver.resolve(KERNEL, new AbortController().signal)).rejects.toMatchObject({
|
|
217
|
+
code: 'TOKEN_EXCHANGE_UNAVAILABLE',
|
|
218
|
+
message: 'Domain issuer discovery could not be reached.',
|
|
219
|
+
cause: native,
|
|
220
|
+
})
|
|
221
|
+
})
|
|
193
222
|
})
|
|
194
223
|
|
|
195
224
|
function exchangeFetch(
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ClientError, TransportError } from '@astrale-os/sdk/client'
|
|
2
|
+
|
|
3
|
+
import type { TransportDiagnosticContext } from '../failure/model'
|
|
4
|
+
|
|
5
|
+
type CompatibleTransportPhase = TransportError['phase'] | 'unknown'
|
|
6
|
+
|
|
7
|
+
export function transportFailure(
|
|
8
|
+
message: string,
|
|
9
|
+
phase: CompatibleTransportPhase,
|
|
10
|
+
context: TransportDiagnosticContext,
|
|
11
|
+
): TransportError {
|
|
12
|
+
const error = new Error(message) as TransportError & {
|
|
13
|
+
context: TransportDiagnosticContext
|
|
14
|
+
}
|
|
15
|
+
Object.setPrototypeOf(error, TransportError.prototype)
|
|
16
|
+
Object.assign(error, { name: 'TransportError', phase, context })
|
|
17
|
+
return error
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function legacyTransportFailure(
|
|
21
|
+
message: string,
|
|
22
|
+
phase: CompatibleTransportPhase,
|
|
23
|
+
delivery: 'not-sent' | 'unknown',
|
|
24
|
+
): TransportError {
|
|
25
|
+
const error = new Error(message) as TransportError & { delivery: typeof delivery }
|
|
26
|
+
Object.setPrototypeOf(error, TransportError.prototype)
|
|
27
|
+
Object.assign(error, { name: 'TransportError', phase, delivery })
|
|
28
|
+
return error
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function sessionFailure(
|
|
32
|
+
message: string,
|
|
33
|
+
failure: 'cancelled' | 'closed' | 'timeout',
|
|
34
|
+
): ClientError {
|
|
35
|
+
const error = new Error(message) as ClientError & { failure: typeof failure }
|
|
36
|
+
Object.setPrototypeOf(error, ClientError.prototype)
|
|
37
|
+
Object.assign(error, { name: 'SessionError', failure })
|
|
38
|
+
return error
|
|
39
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { formatKernelError } from '../errors'
|
|
4
|
+
import { legacyTransportFailure, sessionFailure, transportFailure } from './failure-fixtures'
|
|
5
|
+
|
|
6
|
+
/** @evidence TEST-CLI-CONNECTION-FAILURE-SAFETY */
|
|
7
|
+
test('unknown and empty native failures never become ordinary diagnostics', async () => {
|
|
8
|
+
for (const failure of [new Error('private provider detail'), new Error(''), { secret: true }]) {
|
|
9
|
+
const output = await capture(() => formatKernelError(failure, true))
|
|
10
|
+
expect(JSON.parse(output)).toEqual({
|
|
11
|
+
error: 'UNEXPECTED_ERROR',
|
|
12
|
+
message: 'The CLI encountered an unexpected internal failure.',
|
|
13
|
+
})
|
|
14
|
+
expect(output).not.toContain('private provider detail')
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('Aggregate children are available only under explicit debug output', async () => {
|
|
19
|
+
const failure = new AggregateError([new Error('first private'), new Error('second private')], '')
|
|
20
|
+
const ordinary = await capture(() => formatKernelError(failure, true))
|
|
21
|
+
expect(ordinary).not.toContain('first private')
|
|
22
|
+
expect(ordinary).not.toContain('second private')
|
|
23
|
+
|
|
24
|
+
const debug = await capture(() => formatKernelError(failure, true, '', true))
|
|
25
|
+
expect(debug).toContain('aggregate: Error: first private')
|
|
26
|
+
expect(debug).toContain('aggregate: Error: second private')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('Session and acquisition failures remain typed without unsafe recovery advice', async () => {
|
|
30
|
+
const session = await capture(() =>
|
|
31
|
+
formatKernelError(sessionFailure('Session operation timed out.', 'timeout'), true),
|
|
32
|
+
)
|
|
33
|
+
expect(JSON.parse(session)).toEqual({ error: 'TIMEOUT', message: 'Session operation timed out.' })
|
|
34
|
+
|
|
35
|
+
const acquisition = await capture(() =>
|
|
36
|
+
formatKernelError(
|
|
37
|
+
transportFailure('Publication failed.', 'unknown', {
|
|
38
|
+
kind: 'acquisition',
|
|
39
|
+
resource: 'publication',
|
|
40
|
+
}),
|
|
41
|
+
true,
|
|
42
|
+
'',
|
|
43
|
+
false,
|
|
44
|
+
{ recovery: { operation: 'must-not-leak', retry: 'must-not-leak' } },
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
expect(JSON.parse(acquisition)).toMatchObject({
|
|
48
|
+
error: 'TRANSPORT_ERROR',
|
|
49
|
+
transport: { kind: 'acquisition', resource: 'publication' },
|
|
50
|
+
})
|
|
51
|
+
expect(acquisition).not.toContain('must-not-leak')
|
|
52
|
+
|
|
53
|
+
const legacy = await capture(() =>
|
|
54
|
+
formatKernelError(legacyTransportFailure('Legacy send failed.', 'send', 'not-sent'), true),
|
|
55
|
+
)
|
|
56
|
+
expect(JSON.parse(legacy)).toMatchObject({
|
|
57
|
+
error: 'TRANSPORT_ERROR',
|
|
58
|
+
transport: { kind: 'invocation', delivery: 'not-sent' },
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
async function capture(action: () => Promise<void>): Promise<string> {
|
|
63
|
+
const writes: string[] = []
|
|
64
|
+
const original = process.stderr.write
|
|
65
|
+
process.stderr.write = ((chunk: string | Uint8Array) => {
|
|
66
|
+
writes.push(typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk))
|
|
67
|
+
return true
|
|
68
|
+
}) as typeof process.stderr.write
|
|
69
|
+
try {
|
|
70
|
+
await action()
|
|
71
|
+
return writes.join('')
|
|
72
|
+
} finally {
|
|
73
|
+
process.stderr.write = original
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -2,7 +2,11 @@ import { describe, expect, test } from 'bun:test'
|
|
|
2
2
|
import { SignJWT } from 'jose'
|
|
3
3
|
import { webcrypto } from 'node:crypto'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import type { ConnectionContext } from '../session'
|
|
6
|
+
|
|
7
|
+
import { expandSelfInCall, resolveSelfIdAuthenticated } from '../self'
|
|
8
|
+
|
|
9
|
+
const context = Object.freeze({}) as ConnectionContext
|
|
6
10
|
|
|
7
11
|
describe('resolveSelfIdAuthenticated', () => {
|
|
8
12
|
/** @evidence TEST-CLI-SELF-USES-AUTHENTICATED-EFFECTIVE-PRINCIPAL */
|
|
@@ -14,11 +18,9 @@ describe('resolveSelfIdAuthenticated', () => {
|
|
|
14
18
|
.setSubject('manager-principal')
|
|
15
19
|
.setAudience('https://child.example')
|
|
16
20
|
.sign(key)
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const resolved = await resolveSelfIdAuthenticated(opts, {
|
|
21
|
+
const resolved = await resolveSelfIdAuthenticated(context, {
|
|
20
22
|
whoami: async (received) => {
|
|
21
|
-
expect(received).toBe(
|
|
23
|
+
expect(received).toBe(context)
|
|
22
24
|
return { id: 'child-kernel-principal', slug: 'child' }
|
|
23
25
|
},
|
|
24
26
|
})
|
|
@@ -28,17 +30,35 @@ describe('resolveSelfIdAuthenticated', () => {
|
|
|
28
30
|
|
|
29
31
|
test('resolves an imported root without requiring a local registration', async () => {
|
|
30
32
|
await expect(
|
|
31
|
-
resolveSelfIdAuthenticated(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
),
|
|
33
|
+
resolveSelfIdAuthenticated(context, {
|
|
34
|
+
whoami: async () => ({ id: 'manager-kernel-principal' }),
|
|
35
|
+
}),
|
|
35
36
|
).resolves.toEqual({ id: 'manager-kernel-principal' })
|
|
36
37
|
})
|
|
37
38
|
|
|
38
39
|
test('fails closed when authenticated whoami returns no NodeId', async () => {
|
|
39
40
|
await expect(
|
|
40
|
-
resolveSelfIdAuthenticated(
|
|
41
|
-
).rejects.toMatchObject({
|
|
41
|
+
resolveSelfIdAuthenticated(context, { whoami: async () => ({ id: ' ' }) }),
|
|
42
|
+
).rejects.toMatchObject({ code: 'SELF_RESOLUTION_FAILED' })
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe('expandSelfInCall', () => {
|
|
47
|
+
test('expands only top-level string values after local parameter admission', async () => {
|
|
48
|
+
const callContext = {
|
|
49
|
+
auth: { whoami: async () => ({ id: 'caller-id' }) },
|
|
50
|
+
target: {},
|
|
51
|
+
} as ConnectionContext
|
|
52
|
+
const expanded = await expandSelfInCall(
|
|
53
|
+
'/:people.example.dev:class.Person:get',
|
|
54
|
+
{ owner: '@self', count: 2, nested: { owner: '@self' } },
|
|
55
|
+
callContext,
|
|
56
|
+
)
|
|
57
|
+
expect(expanded.parameters).toEqual({
|
|
58
|
+
owner: '@caller-id',
|
|
59
|
+
count: 2,
|
|
60
|
+
nested: { owner: '@self' },
|
|
61
|
+
})
|
|
42
62
|
})
|
|
43
63
|
})
|
|
44
64
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AuthApi } from '@astrale-os/
|
|
2
|
-
import type { GraphApi } from '@astrale-os/
|
|
3
|
-
import type { ClientSession } from '@astrale-os/
|
|
1
|
+
import type { AuthApi } from '@astrale-os/sdk/auth'
|
|
2
|
+
import type { GraphApi } from '@astrale-os/sdk/client'
|
|
3
|
+
import type { ClientSession } from '@astrale-os/sdk/client/session'
|
|
4
4
|
|
|
5
5
|
import { issuer } from '@astrale-os/sdk/auth'
|
|
6
6
|
import { describe, expect, test } from 'bun:test'
|
package/src/connection/call.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Fetch } from '@astrale-os/
|
|
2
|
-
import type { SessionAuth } from '@astrale-os/
|
|
1
|
+
import type { Fetch } from '@astrale-os/sdk/client'
|
|
2
|
+
import type { SessionAuth } from '@astrale-os/sdk/client/session'
|
|
3
3
|
|
|
4
4
|
import { credential, type IssuerId } from '@astrale-os/sdk/auth'
|
|
5
5
|
|