@output.ai/core 0.1.8-dev.pr156.16605c1 → 0.1.8-dev.pr156.ac53caf
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/package.json
CHANGED
|
@@ -28,15 +28,32 @@ export const init = () => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Get the base path for trace
|
|
32
|
-
*
|
|
31
|
+
* Get the container base path for writing trace files
|
|
32
|
+
* Always writes to the local working directory, regardless of HOST_TRACE_PATH
|
|
33
|
+
* @returns {string} The base path where traces should be written in the container
|
|
34
|
+
*/
|
|
35
|
+
const getContainerBasePath = () => {
|
|
36
|
+
return join( process.cwd(), 'logs' );
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the base path for reporting trace file locations
|
|
41
|
+
* Uses HOST_TRACE_PATH if set (for reporting to host), otherwise uses local path
|
|
42
|
+
* @returns {string} The base path where traces can be accessed from the host
|
|
33
43
|
*/
|
|
34
44
|
const getBasePath = () => {
|
|
35
45
|
return process.env.HOST_TRACE_PATH || join( process.cwd(), 'logs' );
|
|
36
46
|
};
|
|
37
47
|
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Get the output directory for trace files
|
|
50
|
+
* @param {string} workflowName - The name of the workflow
|
|
51
|
+
* @param {boolean} useContainerPath - If true, uses container path for writing; otherwise uses host path for reporting
|
|
52
|
+
* @returns {string} The output directory path
|
|
53
|
+
*/
|
|
54
|
+
const getOutputDir = ( workflowName, useContainerPath = false ) => {
|
|
55
|
+
const basePath = useContainerPath ? getContainerBasePath() : getBasePath();
|
|
56
|
+
return join( basePath, 'runs', workflowName );
|
|
40
57
|
};
|
|
41
58
|
|
|
42
59
|
const buildOutputFileName = ( { startTime, workflowId } ) => {
|
|
@@ -58,7 +75,8 @@ export const exec = ( { entry, executionContext } ) => {
|
|
|
58
75
|
const { workflowId, workflowName, startTime } = executionContext;
|
|
59
76
|
const content = buildTraceTree( accumulate( { entry, executionContext } ) );
|
|
60
77
|
|
|
61
|
-
|
|
78
|
+
// Use container path for writing files (true flag)
|
|
79
|
+
const dir = getOutputDir( workflowName, true );
|
|
62
80
|
const path = join( dir, buildOutputFileName( { startTime, workflowId } ) );
|
|
63
81
|
|
|
64
82
|
mkdirSync( dir, { recursive: true } );
|
|
@@ -29,6 +29,7 @@ describe( 'tracing/processors/local', () => {
|
|
|
29
29
|
vi.clearAllMocks();
|
|
30
30
|
store.files.clear();
|
|
31
31
|
process.argv[2] = '/tmp/project';
|
|
32
|
+
delete process.env.HOST_TRACE_PATH; // Clear HOST_TRACE_PATH for clean tests
|
|
32
33
|
} );
|
|
33
34
|
|
|
34
35
|
it( 'init(): creates temp dir and cleans up old files', async () => {
|
|
@@ -78,5 +79,70 @@ describe( 'tracing/processors/local', () => {
|
|
|
78
79
|
expect( destination ).toMatch( /^\/|^[A-Z]:\\/i ); // Starting with / or Windows drive letter
|
|
79
80
|
expect( destination ).toContain( '/logs/runs/test-workflow/2020-01-02-03-04-05-678Z_workflow-id-123.json' );
|
|
80
81
|
} );
|
|
82
|
+
|
|
83
|
+
it( 'exec(): writes to container path regardless of HOST_TRACE_PATH', async () => {
|
|
84
|
+
const { exec, init } = await import( './index.js' );
|
|
85
|
+
|
|
86
|
+
// Set HOST_TRACE_PATH to simulate Docker environment
|
|
87
|
+
process.env.HOST_TRACE_PATH = '/host/path/logs';
|
|
88
|
+
|
|
89
|
+
init();
|
|
90
|
+
|
|
91
|
+
const startTime = Date.parse( '2020-01-02T03:04:05.678Z' );
|
|
92
|
+
const ctx = { executionContext: { workflowId: 'id1', workflowName: 'WF', startTime } };
|
|
93
|
+
|
|
94
|
+
exec( { ...ctx, entry: { name: 'A', phase: 'start', timestamp: startTime } } );
|
|
95
|
+
|
|
96
|
+
expect( writeFileSyncMock ).toHaveBeenCalledTimes( 1 );
|
|
97
|
+
const [ writtenPath ] = writeFileSyncMock.mock.calls.at( -1 );
|
|
98
|
+
|
|
99
|
+
// Should write to process.cwd()/logs, NOT to HOST_TRACE_PATH
|
|
100
|
+
expect( writtenPath ).not.toContain( '/host/path/logs' );
|
|
101
|
+
expect( writtenPath ).toMatch( /logs\/runs\/WF\// );
|
|
102
|
+
} );
|
|
103
|
+
|
|
104
|
+
it( 'getDestination(): returns HOST_TRACE_PATH when set', async () => {
|
|
105
|
+
const { getDestination } = await import( './index.js' );
|
|
106
|
+
|
|
107
|
+
// Set HOST_TRACE_PATH to simulate Docker environment
|
|
108
|
+
process.env.HOST_TRACE_PATH = '/host/path/logs';
|
|
109
|
+
|
|
110
|
+
const startTime = Date.parse( '2020-01-02T03:04:05.678Z' );
|
|
111
|
+
const workflowId = 'workflow-id-123';
|
|
112
|
+
const workflowName = 'test-workflow';
|
|
113
|
+
|
|
114
|
+
const destination = getDestination( { startTime, workflowId, workflowName } );
|
|
115
|
+
|
|
116
|
+
// Should return HOST_TRACE_PATH-based path for reporting
|
|
117
|
+
expect( destination ).toBe( '/host/path/logs/runs/test-workflow/2020-01-02-03-04-05-678Z_workflow-id-123.json' );
|
|
118
|
+
} );
|
|
119
|
+
|
|
120
|
+
it( 'separation of write and report paths works correctly', async () => {
|
|
121
|
+
const { exec, getDestination, init } = await import( './index.js' );
|
|
122
|
+
|
|
123
|
+
// Set HOST_TRACE_PATH to simulate Docker environment
|
|
124
|
+
process.env.HOST_TRACE_PATH = '/Users/ben/project/logs';
|
|
125
|
+
|
|
126
|
+
init();
|
|
127
|
+
|
|
128
|
+
const startTime = Date.parse( '2020-01-02T03:04:05.678Z' );
|
|
129
|
+
const workflowId = 'workflow-id-123';
|
|
130
|
+
const workflowName = 'test-workflow';
|
|
131
|
+
const ctx = { executionContext: { workflowId, workflowName, startTime } };
|
|
132
|
+
|
|
133
|
+
// Execute to write file
|
|
134
|
+
exec( { ...ctx, entry: { name: 'A', phase: 'start', timestamp: startTime } } );
|
|
135
|
+
|
|
136
|
+
// Get destination for reporting
|
|
137
|
+
const destination = getDestination( { startTime, workflowId, workflowName } );
|
|
138
|
+
|
|
139
|
+
// Verify write path is local
|
|
140
|
+
const [ writtenPath ] = writeFileSyncMock.mock.calls.at( -1 );
|
|
141
|
+
expect( writtenPath ).not.toContain( '/Users/ben/project' );
|
|
142
|
+
expect( writtenPath ).toMatch( /logs\/runs\/test-workflow\// );
|
|
143
|
+
|
|
144
|
+
// Verify report path uses HOST_TRACE_PATH
|
|
145
|
+
expect( destination ).toBe( '/Users/ben/project/logs/runs/test-workflow/2020-01-02-03-04-05-678Z_workflow-id-123.json' );
|
|
146
|
+
} );
|
|
81
147
|
} );
|
|
82
148
|
|