-
Notifications
You must be signed in to change notification settings - Fork 132
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix missing globals #611
fix missing globals #611
Changes from all commits
22f65a9
35a7e07
1c84f93
6e3d84d
a216e0a
ec6b207
87ddd9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import assert from 'node:assert/strict'; | ||
import test, { beforeEach, describe } from 'node:test'; | ||
import { randomHex } from './crypto'; | ||
|
||
describe('randomHex function', () => { | ||
test('should generate a hex string of the correct length', () => { | ||
const size = 16; | ||
const hexString = randomHex(size); | ||
assert.strictEqual(hexString.length, size * 2); | ||
}); | ||
|
||
test('should ensure randomness in generated hex strings', () => { | ||
const size = 16; | ||
const hexString1 = randomHex(size); | ||
const hexString2 = randomHex(size); | ||
assert.notStrictEqual(hexString1, hexString2); | ||
}); | ||
|
||
test('should handle the smallest valid size correctly', () => { | ||
const size = 1; | ||
const hexString = randomHex(size); | ||
assert.strictEqual(hexString.length, 2); | ||
}); | ||
|
||
test('should handle a large size correctly', () => { | ||
const size = 1024; | ||
const hexString = randomHex(size); | ||
assert.strictEqual(hexString.length, size * 2); | ||
}); | ||
|
||
test('should return an empty string for size 0', () => { | ||
const size = 0; | ||
const hexString = randomHex(size); | ||
assert.strictEqual(hexString, ''); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { strict as assert } from 'node:assert'; | ||
import { describe, it as test } from 'node:test'; | ||
import { | ||
serializeError, | ||
errorMessage, | ||
CancelError, | ||
NotSupportedError, | ||
RequestError, | ||
isCancelError, | ||
isRequestError | ||
} from './error'; | ||
|
||
describe('Error Utilities', () => { | ||
describe('serializeError function', () => { | ||
test('should return undefined for null or undefined input', () => { | ||
assert.strictEqual(serializeError(null), undefined); | ||
assert.strictEqual(serializeError(undefined), undefined); | ||
}); | ||
|
||
test('should serialize an Error instance', () => { | ||
const error = new Error('Test error'); | ||
const serialized = serializeError(error); | ||
assert.strictEqual(serialized.message, 'Test error'); | ||
assert.ok('stack' in serialized); | ||
}); | ||
|
||
test('should return the object as is for SerializedError input', () => { | ||
const serializedError = { message: 'Serialized error', stack: 'stack trace' }; | ||
const serialized = serializeError(serializedError); | ||
assert.deepStrictEqual(serialized, serializedError); | ||
}); | ||
|
||
test('should return an object with message property for string input', () => { | ||
const message = 'Test message'; | ||
const serialized = serializeError(message); | ||
assert.strictEqual(serialized.message, message); | ||
}); | ||
|
||
test('should return an object with message property for number input', () => { | ||
const number = 42; | ||
const serialized = serializeError(number); | ||
assert.strictEqual(serialized.message, '42'); | ||
}); | ||
}); | ||
|
||
describe('errorMessage function', () => { | ||
test('should return undefined for null or undefined input', () => { | ||
assert.strictEqual(errorMessage(null), undefined); | ||
assert.strictEqual(errorMessage(undefined), undefined); | ||
}); | ||
|
||
test('should return the error message if available', () => { | ||
const error = new Error('Test error message'); | ||
assert.strictEqual(errorMessage(error), 'Test error message'); | ||
}); | ||
|
||
test('should return default value if no message or name on error', () => { | ||
const error = {}; // Empty error-like object | ||
assert.strictEqual(errorMessage(error), 'error'); | ||
}); | ||
}); | ||
|
||
describe('CancelError class', () => { | ||
test('should have a name property set to "CancelError"', () => { | ||
const error = new CancelError('Cancellation happened'); | ||
assert.strictEqual(error.name, CancelError.NAME); | ||
}); | ||
}); | ||
|
||
describe('NotSupportedError class', () => { | ||
test('should have a name property set to "NotSupportedError"', () => { | ||
const error = new NotSupportedError('Not supported'); | ||
assert.strictEqual(error.name, NotSupportedError.NAME); | ||
}); | ||
}); | ||
|
||
describe('RequestError class', () => { | ||
test('should set instance properties correctly', () => { | ||
const status = 404; | ||
const statusText = 'Not Found'; | ||
const body = { message: 'Resource not found' }; | ||
const bodyText = 'Error body text'; | ||
const retryAfter = 120; | ||
const error = new RequestError(status, statusText, body, bodyText, retryAfter); | ||
assert.strictEqual(error.status, status); | ||
assert.strictEqual(error.statusText, statusText); | ||
assert.deepStrictEqual(error.body, body); | ||
assert.strictEqual(error.bodyText, bodyText); | ||
assert.strictEqual(error.retryAfter, retryAfter); | ||
}); | ||
}); | ||
|
||
describe('isCancelError function', () => { | ||
test('should return true for CancelError instances', () => { | ||
const error = new CancelError('Cancellation'); | ||
assert.ok(isCancelError(error)); | ||
}); | ||
|
||
test('should return true for AbortError', () => { | ||
const error = new Error('Abort'); | ||
error.name = 'AbortError'; | ||
assert.ok(isCancelError(error)); | ||
}); | ||
}); | ||
|
||
describe('isRequestError function', () => { | ||
test('should return true for RequestError instances with matching statusCode and code', () => { | ||
const error = new RequestError(400, 'Bad Request', { code: 'BadRequest' }); | ||
assert.ok(isRequestError(error, 400, 'BadRequest')); | ||
}); | ||
|
||
test('should return true for RequestError instances with undefined statusCode or code', () => { | ||
const error = new RequestError(400, 'Bad Request', { code: 'BadRequest' }); | ||
assert.ok(isRequestError(error)); | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,23 @@ export async function importPrompt( | |
if (!filename) throw new Error("filename is required") | ||
const { trace } = options || {} | ||
|
||
const leakables = [ | ||
"host", | ||
"workspace", | ||
"path", | ||
"parsers", | ||
"env", | ||
"retrieval", | ||
"YAML", | ||
"INI", | ||
"CSV", | ||
"XML", | ||
"JSONL", | ||
"AICI", | ||
"fetchText", | ||
"cancel", | ||
] | ||
|
||
const oldGlb: any = {} | ||
const glb: any = resolveGlobal() | ||
let unregister: () => void = undefined | ||
|
@@ -68,6 +85,7 @@ export async function importPrompt( | |
} finally { | ||
// restore global context | ||
for (const field of Object.keys(oldGlb)) { | ||
if (leakables.includes(field)) continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The array
|
||
const v = oldGlb[field] | ||
if (v === undefined) delete glb[field] | ||
else glb[field] = oldGlb[field] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,12 +111,6 @@ declare var retrieval: Retrieval | |
*/ | ||
declare var workspace: WorkspaceFileSystem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'fs' variable is deprecated. Please make sure to replace all its usages with 'workspace'.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The global variable
|
||
|
||
/** | ||
* Access to the workspace file system. | ||
* @deprecated Use `workspace` instead. | ||
*/ | ||
declare var fs: WorkspaceFileSystem | ||
|
||
/** | ||
* YAML parsing and stringifying functions. | ||
*/ | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
script({ | ||
model: "openai:gpt-3.5-turbo", | ||
tests: { | ||
keywords: ["Python", "3."], | ||
}, | ||
}) | ||
const version = await host.exec("python", ["--version"]) | ||
if (!/^python \d/i.test(version.stdout)) | ||
throw new Error("python --version failed") | ||
defTool( | ||
"python_version", | ||
"determines the version of python on this system", | ||
{}, | ||
async (_) => { | ||
console.debug(`determining python version`) | ||
const version = await host.exec("python", ["--version"]) | ||
return version.stdout?.replace(/^python\s/i, "") || "?" | ||
} | ||
) | ||
$`What is the version of python on this machine?` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array 'leakables' seems to be hard-coded. Consider making it a constant or configurable if these values are used elsewhere or could change.