11import { afterEach , describe , expect , it , vi } from 'bun:test' ;
22import { definition } from '../logic-script' ;
3- import { extractPorts , type ExecutionContext } from '@sentris/component-sdk' ;
3+ import {
4+ extractPorts ,
5+ type DockerRunnerConfig ,
6+ type ExecutionContext ,
7+ } from '@sentris/component-sdk' ;
48import * as sdk from '@sentris/component-sdk' ;
59
610// Mock context
@@ -24,6 +28,12 @@ const mockContext: ExecutionContext = {
2428 } ,
2529} ;
2630
31+ function decodeGeneratedFile ( command : string , filename : 'plugin.ts' | 'harness.ts' ) : string {
32+ const match = command . match ( new RegExp ( `echo "([^"]+)" \\| base64 -d > ${ filename } ` ) ) ;
33+ expect ( match ) . not . toBeNull ( ) ;
34+ return Buffer . from ( match ! [ 1 ] , 'base64' ) . toString ( 'utf8' ) ;
35+ }
36+
2737afterEach ( ( ) => {
2838 vi . restoreAllMocks ( ) ;
2939} ) ;
@@ -65,6 +75,50 @@ describe('Logic/Script Component', () => {
6575 expect ( consoleLogSpy ) . not . toHaveBeenCalled ( ) ;
6676 } ) ;
6777
78+ it ( 'gates sandbox success diagnostics behind component debug logging' , async ( ) => {
79+ const previousDebugFlag = process . env . SENTRIS_DEBUG_COMPONENTS ;
80+ delete process . env . SENTRIS_DEBUG_COMPONENTS ;
81+
82+ const runSpy = vi . spyOn ( sdk , 'runComponentWithRunner' ) . mockResolvedValue ( { sum : 3 } ) ;
83+
84+ try {
85+ await definition . execute (
86+ {
87+ inputs : { } ,
88+ params : {
89+ code : 'export async function script() { return { sum: 1 + 2 }; }' ,
90+ variables : [ ] ,
91+ returns : [ { name : 'sum' , type : 'number' } ] ,
92+ } ,
93+ } ,
94+ mockContext ,
95+ ) ;
96+
97+ const [ runnerConfig ] = runSpy . mock . calls [ 0 ] as [ DockerRunnerConfig , ...unknown [ ] ] ;
98+ const command = runnerConfig . command . join ( ' ' ) ;
99+ const pluginSource = decodeGeneratedFile ( command , 'plugin.ts' ) ;
100+ const harnessSource = decodeGeneratedFile ( command , 'harness.ts' ) ;
101+
102+ expect ( runnerConfig . env ) . toEqual ( { SENTRIS_DEBUG_COMPONENTS : '' } ) ;
103+ expect ( pluginSource ) . toContain ( 'SENTRIS_DEBUG_COMPONENTS' ) ;
104+ expect ( harnessSource ) . toContain ( 'SENTRIS_DEBUG_COMPONENTS' ) ;
105+ expect ( pluginSource ) . not . toContain ( 'console.log("[http-loader] Fetching:", href);' ) ;
106+ expect ( harnessSource ) . not . toContain ( "console.log('[Script] Starting execution...');" ) ;
107+ expect ( harnessSource ) . not . toContain (
108+ "console.log('[Script] Execution completed, writing output...');" ,
109+ ) ;
110+ expect ( harnessSource ) . not . toContain (
111+ "console.log('[Script] Output written to', OUTPUT_PATH);" ,
112+ ) ;
113+ } finally {
114+ if ( previousDebugFlag === undefined ) {
115+ delete process . env . SENTRIS_DEBUG_COMPONENTS ;
116+ } else {
117+ process . env . SENTRIS_DEBUG_COMPONENTS = previousDebugFlag ;
118+ }
119+ }
120+ } ) ;
121+
68122 it ( 'transpiles and executes TypeScript' , async ( ) => {
69123 vi . spyOn ( sdk , 'runComponentWithRunner' ) . mockResolvedValue ( { msg : 'Value is 10' } ) ;
70124 const tsCode = `
0 commit comments