Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/commands/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,22 @@ export async function computeStatus(serviceName: string | undefined, opts: LifeO
const id = resolveComputeServiceId(services, serviceName)
const r = await api.request('GET', `/projects/${p.projectId}/services/${id}/state`)
if (opts.json) return printJson(r)
info(`compute ${serviceName ?? id}: desired=${r.desiredState} live=${r.state}`)
for (const line of statusLines(serviceName ?? id, r)) info(line)
}

type LastFailure = { kind: 'deploy' | 'build'; at: string; reason: string; buildId?: string; buildSource?: 'github' | 'archive' }

/** `insta compute status` lines. The platform sends `lastFailure` only while the newest deploy
* attempt is a failure, so `live=none` comes with its reason instead of sending the user to dig
* through `compute repo --json` or the build record (insta-platform #646). */
export function statusLines(label: string, r: { desiredState?: string; state?: string; lastFailure?: LastFailure }): string[] {
const lines = [`compute ${label}: desired=${r.desiredState} live=${r.state}`]
const f = r.lastFailure
if (!f) return lines
const at = Number.isNaN(Date.parse(f.at)) ? f.at : `${new Date(f.at).toISOString().slice(0, 16).replace('T', ' ')} UTC`
lines.push(`last ${f.kind} failed ${at}: ${f.reason}`)
if (f.buildId) lines.push(` → insta build logs ${f.buildId} --source ${f.buildSource ?? 'github'}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The build-logs hint silently assumes --source github when the platform omits buildSource, but the build logs command itself defaults to --source archive (src/index.ts:545), and archive sources take deploy-operation IDs while github sources take GitHub build IDs. If the platform ever sends buildId without buildSource (the type here allows exactly that combination), a user debugging a failed archive/source-dir deploy would be handed 'insta build logs <op-id> --source github', which reads the wrong record. Since the companion platform work defines this contract, either guarantee buildSource whenever buildId is present and drop the github fallback, or only emit the hint when the source is known.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/commands/compute.ts, line 428:

<comment>The build-logs hint silently assumes --source github when the platform omits buildSource, but the build logs command itself defaults to --source archive (src/index.ts:545), and archive sources take deploy-operation IDs while github sources take GitHub build IDs. If the platform ever sends buildId without buildSource (the type here allows exactly that combination), a user debugging a failed archive/source-dir deploy would be handed 'insta build logs <op-id> --source github', which reads the wrong record. Since the companion platform work defines this contract, either guarantee buildSource whenever buildId is present and drop the github fallback, or only emit the hint when the source is known.</comment>

<file context>
@@ -411,7 +411,22 @@ export async function computeStatus(serviceName: string | undefined, opts: LifeO
+  if (!f) return lines
+  const at = Number.isNaN(Date.parse(f.at)) ? f.at : `${new Date(f.at).toISOString().slice(0, 16).replace('T', ' ')} UTC`
+  lines.push(`last ${f.kind} failed ${at}: ${f.reason}`)
+  if (f.buildId) lines.push(`  → insta build logs ${f.buildId} --source ${f.buildSource ?? 'github'}`)
+  return lines
 }
</file context>

return lines
}

// ---- exec (one-shot command; no interactive shell/PTY) ----
Expand Down
32 changes: 32 additions & 0 deletions test/compute-status.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// `insta compute status` rendering: `live=none` must come with the reason the newest deploy
// attempt failed, and the build-logs command when it was a build (insta-platform #646).
import { describe, it, expect } from 'vitest'
import { statusLines } from '../src/commands/compute.js'

describe('statusLines', () => {
it('prints only desired vs live when the platform sends no failure', () => {
expect(statusLines('api', { desiredState: 'running', state: 'running' })).toEqual(['compute api: desired=running live=running'])
})

it('prints the failure reason and the build-logs command for a repo build', () => {
expect(statusLines('api', {
desiredState: 'running', state: 'none',
lastFailure: { kind: 'deploy', at: '2026-10-08T09:34:03.123Z', reason: 'app on the vm not ready (listening on :8080) within 2m0s', buildId: '6a20f7bb-0000-4000-8000-000000000000', buildSource: 'github' },
})).toEqual([
'compute api: desired=running live=none',
'last deploy failed 2026-10-08 09:34 UTC: app on the vm not ready (listening on :8080) within 2m0s',
' → insta build logs 6a20f7bb-0000-4000-8000-000000000000 --source github',
])
})

it('names an archive build source and a build-phase failure', () => {
const lines = statusLines('api', { desiredState: 'running', state: 'none', lastFailure: { kind: 'build', at: '2026-10-08T09:34:03Z', reason: 'no Dockerfile', buildId: 'op-1', buildSource: 'archive' } })
expect(lines[1]).toBe('last build failed 2026-10-08 09:34 UTC: no Dockerfile')
expect(lines[2]).toBe(' → insta build logs op-1 --source archive')
})

it('an image deploy has no build to point at', () => {
expect(statusLines('api', { desiredState: 'running', state: 'stopped', lastFailure: { kind: 'deploy', at: '2026-10-08T09:34:03Z', reason: 'nothing on 8080' } }))
.toEqual(['compute api: desired=running live=stopped', 'last deploy failed 2026-10-08 09:34 UTC: nothing on 8080'])
})
})
Loading