Skip to content

Commit 732b4c0

Browse files
committed
address stdin content review comments
1 parent 603a4ae commit 732b4c0

5 files changed

Lines changed: 58 additions & 6 deletions

File tree

src/cli/actions/defaultAction.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type RepomixOutputStyle,
99
repomixConfigCliSchema,
1010
} from '../../config/configSchema.js';
11-
import { readContentFromStdin, readFilePathsFromStdin } from '../../core/file/fileStdin.js';
11+
import { readFilePathsFromStdin } from '../../core/file/fileStdin.js';
1212
import { type PackResult, pack } from '../../core/packager.js';
1313
import { generateDefaultSkillName } from '../../core/skill/skillUtils.js';
1414
import { RepomixError, rethrowValidationErrorIfSchemaError } from '../../shared/errorHandle.js';
@@ -61,10 +61,6 @@ export const runDefaultAction = async (
6161
): Promise<DefaultActionRunnerResult> => {
6262
logger.trace('Loaded CLI options:', cliOptions);
6363

64-
if (cliOptions.stdinContent === true) {
65-
cliOptions.stdinContent = await readContentFromStdin();
66-
}
67-
6864
// Build the merged config (migration + file config + CLI options)
6965
const config = await buildMergedConfig(cwd, cliOptions);
7066

src/cli/cliRun.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ export const runCli = async (directories: string[], cwd: string, options: CliOpt
304304
throw new RepomixError('--stdin cannot be used with --stdin-content. Both options consume standard input.');
305305
}
306306

307+
if (options.stdinContent === true) {
308+
const { readContentFromStdin } = await import('../core/file/fileStdin.js');
309+
options.stdinContent = await readContentFromStdin();
310+
}
311+
307312
// Set log level based on verbose and quiet flags
308313
if (options.quiet) {
309314
logger.setLogLevel(repomixLogLevels.SILENT);

src/core/output/outputGenerate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const generateParsableJsonOutput = async (renderContext: RenderContext): Promise
177177
...(renderContext.headerText && {
178178
userProvidedHeader: renderContext.headerText,
179179
}),
180-
...(renderContext.stdinContent && {
180+
...(renderContext.stdinContent !== undefined && {
181181
stdinContent: renderContext.stdinContent,
182182
}),
183183
...(renderContext.directoryStructureEnabled && {

tests/cli/cliRun.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as remoteAction from '../../src/cli/actions/remoteAction.js';
77
import * as versionAction from '../../src/cli/actions/versionAction.js';
88
import { run, runCli } from '../../src/cli/cliRun.js';
99
import type { CliOptions } from '../../src/cli/types.js';
10+
import * as fileStdin from '../../src/core/file/fileStdin.js';
1011
import * as gitRemoteHandle from '../../src/core/git/gitRemoteHandle.js';
1112
import type { PackResult } from '../../src/core/packager.js';
1213
import { logger, type RepomixLogLevel, repomixLogLevels } from '../../src/shared/logger.js';
@@ -226,6 +227,39 @@ describe('cliRun', () => {
226227
expect(defaultAction.runDefaultAction).not.toHaveBeenCalled();
227228
});
228229

230+
test('should resolve stdin content before executing default action', async () => {
231+
vi.spyOn(fileStdin, 'readContentFromStdin').mockResolvedValue('npm run build failed');
232+
233+
await runCli(['.'], process.cwd(), {
234+
stdinContent: true,
235+
});
236+
237+
expect(defaultAction.runDefaultAction).toHaveBeenCalledWith(
238+
['.'],
239+
process.cwd(),
240+
expect.objectContaining({
241+
stdinContent: 'npm run build failed',
242+
}),
243+
);
244+
});
245+
246+
test('should resolve stdin content before executing remote action', async () => {
247+
vi.spyOn(fileStdin, 'readContentFromStdin').mockResolvedValue('remote build failed');
248+
249+
await runCli(['.'], process.cwd(), {
250+
remote: 'yamadashy/repomix',
251+
stdinContent: true,
252+
});
253+
254+
expect(remoteAction.runRemoteAction).toHaveBeenCalledWith(
255+
'yamadashy/repomix',
256+
expect.objectContaining({
257+
stdinContent: 'remote build failed',
258+
}),
259+
);
260+
expect(defaultAction.runDefaultAction).not.toHaveBeenCalled();
261+
});
262+
229263
test('should auto-detect HTTPS URL and execute remote action', async () => {
230264
await runCli(['https://github.com/user/repo'], process.cwd(), {});
231265

tests/core/output/outputStyles/jsonStyle.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ describe('JSON Output Style', () => {
124124
expect(parsed.stdinContent).toBe('npm run build failed');
125125
});
126126

127+
test('should preserve empty stdinContent when provided', async () => {
128+
const config = createMockConfig({
129+
output: {
130+
...createMockConfig().output,
131+
stdinContent: '',
132+
},
133+
});
134+
const processedFiles = createMockProcessedFiles();
135+
const allFilePaths = processedFiles.map((f) => f.path);
136+
137+
const result = await generateOutput(['/test'], config, processedFiles, allFilePaths);
138+
const parsed = JSON.parse(result);
139+
140+
expect(Object.hasOwn(parsed, 'stdinContent')).toBe(true);
141+
expect(parsed.stdinContent).toBe('');
142+
});
143+
127144
test('should include files when enabled', async () => {
128145
const config = createMockConfig({
129146
output: {

0 commit comments

Comments
 (0)