11import { describe , it , expect } from 'vitest'
2- import { serializeEnv , handleApproval } from '../src/util.js'
2+ import { serializeEnv , handleApproval , nextActionsLines } from '../src/util.js'
33
44describe ( 'serializeEnv' , ( ) => {
55 it ( 'quotes and escapes values; ends with newline' , ( ) => {
@@ -22,3 +22,35 @@ describe('handleApproval', () => {
2222 expect ( handleApproval ( { status : 200 , body : { ok : true } } ) ) . toBe ( false )
2323 } )
2424} )
25+
26+ describe ( 'nextActionsLines' , ( ) => {
27+ it ( 'renders a mapped op as an insta command with args, plus its reason' , ( ) => {
28+ const lines = nextActionsLines ( [ { op : 'service.add' , reason : 'Add a service first.' , args : { type : 'postgres' , name : 'db' } } ] )
29+ expect ( lines [ 0 ] ) . toBe ( 'Next:' )
30+ expect ( lines . join ( '\n' ) ) . toContain ( 'insta services add postgres db' )
31+ expect ( lines . join ( '\n' ) ) . toContain ( 'Add a service first.' )
32+ } )
33+
34+ it ( 'degrades to reason-only for an unknown op and never crashes' , ( ) => {
35+ const lines = nextActionsLines ( [ { op : 'totally.unknown' , reason : 'Do the thing.' } ] )
36+ expect ( lines . join ( '\n' ) ) . toContain ( 'Do the thing.' )
37+ } )
38+
39+ it ( 'marks gated actions' , ( ) => {
40+ const lines = nextActionsLines ( [ { op : 'deploy' , reason : 'Deploy it.' , gated : true , args : { } } ] )
41+ expect ( lines . join ( '\n' ) ) . toContain ( 'needs approval' )
42+ } )
43+
44+ it ( 'returns [] for empty/absent input' , ( ) => {
45+ expect ( nextActionsLines ( undefined ) ) . toEqual ( [ ] )
46+ expect ( nextActionsLines ( [ ] ) ) . toEqual ( [ ] )
47+ } )
48+
49+ it ( 'renders metrics/logs hints with the compute target (runnable command)' , ( ) => {
50+ const metricsLines = nextActionsLines ( [ { op : 'metrics' , reason : 'Check metrics.' , args : { projectId : 'pr_1' } } ] )
51+ expect ( metricsLines . join ( '\n' ) ) . toContain ( 'insta metrics compute' )
52+
53+ const logsLines = nextActionsLines ( [ { op : 'logs' , reason : 'Check logs.' , args : { projectId : 'pr_1' } } ] )
54+ expect ( logsLines . join ( '\n' ) ) . toContain ( 'insta logs compute' )
55+ } )
56+ } )
0 commit comments