-
Notifications
You must be signed in to change notification settings - Fork 61
馃 feat: Add Opt-In RTK Shell Output Filtering #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danny-avila
wants to merge
4
commits into
main
Choose a base branch
from
danny-avila/optional-rtk-output-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
235f57e
feat: add opt-in RTK shell output filtering
danny-avila 98d6fbf
fix: address RTK self-review findings
danny-avila 13b5915
fix: detect BASH_SOURCE expansions precisely
danny-avila f09636c
fix: preserve RTK filtering across Bash runtimes
danny-avila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| Code Interpreter | ||
| Copyright 2026 ClickHouse, Inc. | ||
|
|
||
| This product includes RTK v0.45.0 (https://github.com/rtk-ai/rtk), | ||
| Copyright 2024 Patrick Szymkowiak, licensed under the Apache License 2.0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; | ||
| import { execFileSync } from 'node:child_process'; | ||
| import * as fs from 'node:fs'; | ||
| import * as os from 'node:os'; | ||
| import * as path from 'node:path'; | ||
|
|
||
| const wrapper = path.resolve(__dirname, '../../docker/bash-run.sh'); | ||
|
|
||
| describe('Bash RTK run wrapper', () => { | ||
| let tempDir: string; | ||
| let sourcePath: string; | ||
| let mockBin: string; | ||
|
|
||
| beforeEach(() => { | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codeapi-rtk-test-')); | ||
| sourcePath = path.join(tempDir, 'script.sh'); | ||
| mockBin = path.join(tempDir, 'bin'); | ||
| fs.mkdirSync(mockBin); | ||
| fs.writeFileSync(sourcePath, "printf 'raw:%s\\n' \"${1:-none}\"\n"); | ||
| fs.writeFileSync(path.join(mockBin, 'rtk'), `#!/bin/bash | ||
| case "\${MOCK_RTK_STATUS:-0}" in | ||
| 0|3) printf '%s\\n' 'printf '\"'\"'filtered:%s\\n'\"'\"' "$1"' ;; | ||
| *) printf '%s\\n' 'printf '\"'\"'must-not-run\\n'\"'\"'' ;; | ||
| esac | ||
| exit "\${MOCK_RTK_STATUS:-0}" | ||
| `); | ||
| fs.chmodSync(path.join(mockBin, 'rtk'), 0o755); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function run(options: { | ||
| filter?: 'raw' | 'rtk'; | ||
| status?: number; | ||
| args?: string[]; | ||
| } = {}): string { | ||
| return execFileSync('bash', [wrapper, sourcePath, ...(options.args ?? [])], { | ||
| encoding: 'utf8', | ||
| env: { | ||
| ...process.env, | ||
| PATH: `${mockBin}:${process.env.PATH ?? '/usr/bin:/bin'}`, | ||
| CODEAPI_SHELL_OUTPUT_FILTER: options.filter ?? 'raw', | ||
| MOCK_RTK_STATUS: String(options.status ?? 0), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| it('preserves raw execution when the request does not opt in', () => { | ||
| expect(run()).toBe('raw:none\n'); | ||
| }); | ||
|
|
||
| it('executes RTK rewrites and preserves user script arguments', () => { | ||
| expect(run({ filter: 'rtk', args: ['argument'] })).toBe('filtered:argument\n'); | ||
| }); | ||
|
|
||
| it('preserves the submitted path as $0 and BASH_ARGV0 for rewrites', () => { | ||
| fs.writeFileSync(path.join(mockBin, 'rtk'), `#!/bin/bash | ||
| printf '%s\\n' 'printf "identity:%s:%s:%s\\n" "$0" "$BASH_ARGV0" "$1"' | ||
| `); | ||
| fs.chmodSync(path.join(mockBin, 'rtk'), 0o755); | ||
|
|
||
| expect(run({ filter: 'rtk', args: ['argument'] })).toBe( | ||
| `identity:${sourcePath}:${sourcePath}:argument\n`, | ||
| ); | ||
| }); | ||
|
|
||
| it('preserves file execution for scripts that inspect BASH_SOURCE', () => { | ||
| fs.writeFileSync( | ||
| sourcePath, | ||
| 'printf \'identity:%s:%s\\n\' "${BASH_SOURCE[0]}" "$0"\n', | ||
| ); | ||
|
|
||
| expect(run({ filter: 'rtk' })).toBe(`identity:${sourcePath}:${sourcePath}\n`); | ||
| }); | ||
|
|
||
| it('preserves file execution for BASH_SOURCE transformations', () => { | ||
| fs.writeFileSync( | ||
| sourcePath, | ||
| ': "${BASH_SOURCE@Q}" "${BASH_SOURCE^^}" "${BASH_SOURCE,,}"\nprintf \'raw\\n\'\n', | ||
| ); | ||
|
|
||
| expect(run({ filter: 'rtk' })).toBe('raw\n'); | ||
| }); | ||
|
|
||
| it('rewrites scripts that only mention BASH_SOURCE literally', () => { | ||
| fs.writeFileSync( | ||
| sourcePath, | ||
| "# BASH_SOURCE is only documented here\nprintf 'BASH_SOURCE is just text\\n'\n", | ||
| ); | ||
|
|
||
| expect(run({ filter: 'rtk' })).toBe('filtered:\n'); | ||
| }); | ||
|
|
||
| it('accepts RTK ask rewrites because the API request already authorizes execution', () => { | ||
| expect(run({ filter: 'rtk', status: 3 })).toBe('filtered:\n'); | ||
| }); | ||
|
|
||
| it('fails open to the original script when RTK cannot rewrite the command', () => { | ||
| expect(run({ filter: 'rtk', status: 1, args: ['original'] })).toBe('raw:original\n'); | ||
| expect(run({ filter: 'rtk', status: 2, args: ['original'] })).toBe('raw:original\n'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.