-
Notifications
You must be signed in to change notification settings - Fork 7
feat(integrations): agentbox doctor reports each connector + Notion docs (T3) #75
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
Merged
Merged
Changes from all commits
Commits
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
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,127 @@ | ||
| /** | ||
| * Unit tests for the `integrations:` group in `agentbox doctor`. | ||
| * | ||
| * The real `ntn` lives only on the host (this box can't install it), so the | ||
| * test stages a tiny shell script named `ntn` on a private PATH and asserts | ||
| * the four meaningful transitions: disabled → info, enabled+missing → warn, | ||
| * enabled+present-but-unauthed → warn (with the login hint), enabled+ok → ok. | ||
| * | ||
| * Config is injected via the `IntegrationsConfigLoader` parameter rather than | ||
| * touched on disk — same pattern `refuseIfIntegrationDisabled` uses in the | ||
| * relay, so the test stays pure (no `~/.agentbox` touch). | ||
| */ | ||
|
|
||
| import { chmod, mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
| import { | ||
| integrationsChecks, | ||
| type IntegrationsConfigLoader, | ||
| } from '../src/lib/doctor-checks.js'; | ||
|
|
||
| const NTN_SCRIPT = `#!/usr/bin/env bash | ||
| case "$1" in | ||
| --version) | ||
| echo "ntn version 0.42.0" | ||
| exit 0 ;; | ||
| api) | ||
| if [ "$NTN_TEST_AUTH" = "ok" ]; then | ||
| echo '{"object":"user","id":"stub"}' | ||
| exit 0 | ||
| fi | ||
| echo "Error: not logged in. Run 'ntn login' to authenticate." >&2 | ||
| exit 1 ;; | ||
| *) | ||
| echo "stub: unknown subcommand $1" >&2 | ||
| exit 2 ;; | ||
| esac | ||
| `; | ||
|
|
||
| const enabled: IntegrationsConfigLoader = () => | ||
| Promise.resolve({ effective: { integrations: { notion: { enabled: true } } } }); | ||
| const disabled: IntegrationsConfigLoader = () => Promise.resolve({ effective: {} }); | ||
|
|
||
| describe('doctor — integrations group', () => { | ||
| let stubDir: string; | ||
| let originalPath: string | undefined; | ||
| let originalAuth: string | undefined; | ||
|
|
||
| beforeEach(async () => { | ||
| stubDir = await mkdtemp(join(tmpdir(), 'agentbox-doctor-int-')); | ||
| originalPath = process.env.PATH; | ||
| originalAuth = process.env.NTN_TEST_AUTH; | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| if (originalPath === undefined) delete process.env.PATH; | ||
| else process.env.PATH = originalPath; | ||
| if (originalAuth === undefined) delete process.env.NTN_TEST_AUTH; | ||
| else process.env.NTN_TEST_AUTH = originalAuth; | ||
| await rm(stubDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| async function stageStub(): Promise<void> { | ||
| const ntn = join(stubDir, 'ntn'); | ||
| await writeFile(ntn, NTN_SCRIPT, 'utf8'); | ||
| await chmod(ntn, 0o755); | ||
| // Prepend the stub dir so our fake `ntn` wins over any real one, but | ||
| // keep the original PATH so the script's `#!/usr/bin/env bash` shebang | ||
| // can still resolve `bash` (env in /usr/bin uses the child's PATH). | ||
| process.env.PATH = `${stubDir}:${originalPath ?? ''}`; | ||
| } | ||
|
|
||
| function emptyPath(): void { | ||
| // Only the empty stub dir — execa(`ntn`) gets ENOENT directly (no | ||
| // shebang interpretation needed for a missing binary). | ||
| process.env.PATH = stubDir; | ||
| } | ||
|
|
||
| it('renders info / "disabled" when the flag is off (default)', async () => { | ||
| emptyPath(); | ||
| const results = await integrationsChecks(disabled); | ||
| expect(results).toHaveLength(1); | ||
| const row = results[0]!; | ||
| expect(row.label).toBe('notion'); | ||
| expect(row.status).toBe('info'); | ||
| expect(row.detail).toBe('disabled'); | ||
| expect(row.hint).toContain('integrations.notion.enabled true'); | ||
| }); | ||
|
|
||
| it('renders warn / "not installed" when enabled but ntn is missing', async () => { | ||
| emptyPath(); | ||
| const results = await integrationsChecks(enabled); | ||
| const row = results[0]!; | ||
| expect(row.status).toBe('warn'); | ||
| expect(row.detail).toMatch(/not installed/); | ||
| expect(row.hint).toMatch(/install ntn/); | ||
| }); | ||
|
|
||
| it('renders warn / "not logged in" when ntn is present but unauthed', async () => { | ||
| await stageStub(); | ||
| delete process.env.NTN_TEST_AUTH; | ||
| const results = await integrationsChecks(enabled); | ||
| const row = results[0]!; | ||
| expect(row.status).toBe('warn'); | ||
| expect(row.detail).toBe('not logged in'); | ||
| expect(row.hint).toBe('ntn login'); | ||
| }); | ||
|
|
||
| it('renders ok with the version line when ntn is present and authed', async () => { | ||
| await stageStub(); | ||
| process.env.NTN_TEST_AUTH = 'ok'; | ||
| const results = await integrationsChecks(enabled); | ||
| const row = results[0]!; | ||
| expect(row.status).toBe('ok'); | ||
| expect(row.detail).toContain('ntn version 0.42.0'); | ||
| expect(row.detail).toContain('authed'); | ||
| }); | ||
|
|
||
| it('fails closed (no throw) when the config loader rejects', async () => { | ||
| emptyPath(); | ||
| const broken: IntegrationsConfigLoader = () => | ||
| Promise.reject(new Error('malformed yaml')); | ||
| const results = await integrationsChecks(broken); | ||
| expect(results[0]?.status).toBe('info'); | ||
| }); | ||
| }); |
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.
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.
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.
Auth probe lacks timeout
Medium Severity
When Notion is enabled,
checkOneIntegrationrunsprobeIntegrationBinforauthArgs(ntn api v1/users/me) with noexecatimeout, so a slow or stuck network call can leaveagentbox doctorhanging unlike relay integration RPCs, which cap host CLI time.Reviewed by Cursor Bugbot for commit 404a23f. Configure here.