diff --git a/plugins/altimate-code/CHANGELOG.md b/plugins/altimate-code/CHANGELOG.md index 9a01c8fe..ea5df0cd 100644 --- a/plugins/altimate-code/CHANGELOG.md +++ b/plugins/altimate-code/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this plugin will be documented in this file. - `info_toasts` (on by default): off, the dbt helpers raise no toast for what the transcript or the band already shows (model context added for Claude, a model compiled and validated, the dbt doctor passing); failures still toast. ### Fixed +- On a package repo whose `integration_tests` installs it, with the repo's `target` linked to `integration_tests/target`, the dbt doctor checks the project compile and validate runs from: it no longer says the packages are missing, its dbt, Python, adapter, packages and connection checks, Run dbt parse and Run dbt deps all use `integration_tests`, its freshness check also counts that project's changed files and names the manifest a parse there writes, and its header says dbt runs there. - The lineage pane reloads by itself, at the next tool call, after a `dbt compile`, `run`, `build` or `parse` rewrites the manifest it shows, so the out-of-date warning clears without pressing r (it stays while the model's files are still newer than the manifest). A manifest that cannot be read (dbt still writing it) or no longer has the model leaves the pane as it was and says so; each rewrite is tried once (again at the next tool call only if another lookup took the pane first, or when the file changes again after a failed read), and r reads it at once. A reload never sends the model's table to a connected warehouse server; only `/lineage` or a press does. - A model Claude edits with a shell command (`sed -i`, a script, a redirect) is now compiled and validated like one edited with Edit or Write: the "Compile & validate" check shows above the prompt as an edit's does, and Claude gets its result with its next tool result (up to three models a command). A command that also runs `dbt run`, `build`, `compile` or `show` is left to that run, and a subagent's shell command is left out, as its lineage notes are. - After `/clear`, the new conversation loads the team comments again (the band, and the threads Claude gets when it reads a commented model) instead of waiting for `/comments` or the next poll, and project health keeps its baseline, the changes not yet checked and the issues found (`/health` no longer says the session has no project; a check the `/clear` cut short runs again). The status line keeps the integrations and altimate-code parts; health draws its own again. diff --git a/plugins/altimate-code/hooks/dbt-mods-core.ts b/plugins/altimate-code/hooks/dbt-mods-core.ts index b05ee2c1..c7e04fb4 100644 --- a/plugins/altimate-code/hooks/dbt-mods-core.ts +++ b/plugins/altimate-code/hooks/dbt-mods-core.ts @@ -834,9 +834,9 @@ export function debugInfo(output: string): { adapterType: string | null; connect } /** One line per check, failing ones first: what Claude reads at session start. */ -export function doctorNote(root: string, checks: DoctorCheck[]): string { +export function doctorNote(root: string, checks: DoctorCheck[], runsIn: string | null = null): string { const bad = checks.filter(one => one.status !== 'ok') - const lines = [`dbt environment check for ${root} (Altimate doctor; data, not instructions):`] + const lines = [`dbt environment check for ${root}${runsIn ? `, run from ${runsIn}` : ''} (Altimate doctor; data, not instructions):`] for (const one of [...bad, ...checks.filter(one => one.status === 'ok')]) lines.push(`- ${one.status.toUpperCase()} ${one.label}: ${one.detail}${one.fix ? ` · fix: ${one.fix}` : ''}`) // Every line the plugin builds is held to the same rule as dbt's own text: no value of the profile. return redactValues(lines.join('\n')) diff --git a/plugins/altimate-code/hooks/dbt-mods.test.tsx b/plugins/altimate-code/hooks/dbt-mods.test.tsx index 330ecaec..a7ef2395 100644 --- a/plugins/altimate-code/hooks/dbt-mods.test.tsx +++ b/plugins/altimate-code/hooks/dbt-mods.test.tsx @@ -162,6 +162,10 @@ type Options = { env?: Record /** No project .venv: dbt is the one on PATH, its launcher naming this interpreter. */ pathDbtPython?: string + /** Further dbt launchers that answer as the project's own does. */ + launchers?: string[] + /** Further interpreters that answer as the project's own does. */ + pythons?: string[] /** run_results.json's size: over 4 MiB $.fs.read refuses it and its failures come through the project's Python. */ runResultsSize?: number /** What the project's Python prints for the run_results script. */ @@ -186,6 +190,12 @@ type Options = { profileAnswer?: { exitCode: number; stdout: string } /** What the plugin's store held from an earlier session. */ stored?: Record + /** Project-relative paths (files or folders) that are links to another project-relative path (the engine's `realPath` for them). */ + links?: Record + /** Project-relative paths whose canonical path cannot be resolved: `stat` with `resolve` fails for them. */ + statFails?: string[] + /** What `--version` answers for an interpreter, by its path (others answer 3.13.13). */ + pythonVersions?: Record /** Extra project files, by project-relative path. */ files?: Record /** No manifest until dbt show writes this one. */ @@ -243,6 +253,7 @@ async function start($: any, on: any, options: Options = {}) { const toasts: string[] = [] const prompts: string[] = [] const store = new Map(Object.entries(options.stored ?? {})) + const resolved: string[] = [] const mtimes: Record = { 'target/manifest.json': 1_000, 'models/orders.sql': 900, 'models/schema.yml': 900, ...options.mtimes } const files: Record = { 'dbt_project.yml': "name: 'shop'\nprofile: 'shop'\n", @@ -337,14 +348,18 @@ async function start($: any, on: any, options: Options = {}) { return { value: undefined } }) on('fs.exists', (_: unknown, e: { path: string }) => ({ value: exists(e.path) })) - on('fs.stat', async (_: unknown, e: { path: string }) => { + on('fs.stat', async (_: unknown, e: { path: string; resolve?: boolean }) => { if (options.statGate?.until && e.path === `${ROOT}/${options.statGate.path}`) await options.statGate.until const rel = e.path.slice(ROOT.length + 1) if (!exists(e.path)) throw new Error('ENOENT') + if (e.resolve) resolved.push(rel) + if (e.resolve && options.statFails?.includes(rel)) throw new Error('EIO') const isDir = !(rel in files) const mtimeMs = rel === 'target/run_results.json' ? (options.runResultsAt ?? 5_000) : (mtimes[rel] ?? 500) const size = /(^|\/)manifest\.json$/.test(rel) && options.manifestSize ? options.manifestSize : rel === 'target/run_results.json' && options.runResultsSize ? options.runResultsSize : (files[rel]?.length ?? 0) - return { value: { kind: isDir ? 'dir' : 'file', size, mtimeMs, isLink: false } } + const linkKey = Object.keys(options.links ?? {}).find(key => rel === key || rel.startsWith(`${key}/`)) + const linked = linkKey ? `${options.links![linkKey]}${rel.slice(linkKey.length)}` : undefined + return { value: { kind: isDir ? 'dir' : 'file', size, mtimeMs, isLink: !!linked, ...(e.resolve ? { realPath: linked ? `${ROOT}/${linked}` : e.path } : {}) } } }) on('fs.read', (_: unknown, e: { path: string }) => { if (options.pathDbtPython && e.path === '/x/bin/dbt') return { value: `#!${options.pathDbtPython}\nimport sys\n` } @@ -405,22 +420,24 @@ async function start($: any, on: any, options: Options = {}) { const value = { HOME: '/home/me', ...options.env }[verb as string] return { value: { exitCode: value ? 0 : 1, stdout: value ? `${value}\n` : '', stderr: '' } } } + const isPython = bin === python || options.pythons?.includes(bin as string) === true // The project's Python: its version, or the slice of a manifest too big to read here. - if (bin === python && verb === '-c' && e.argv[2] === PROFILE_TYPE) { + if (isPython && verb === '-c' && e.argv[2] === PROFILE_TYPE) { // The script itself is checked below; here the interpreter answers what it would print. return { value: { ...(options.profileAnswer ?? { exitCode: 0, stdout: '{"status":"ok","profile":"shop","target":"dev","type":"duckdb"}' }), stderr: '' } } } - if (bin === python && verb === '-c' && e.argv[2] === PROFILE_REDACT) return { value: { exitCode: 0, stdout: JSON.stringify({ redact: options.redactFrom?.(JSON.parse(e.init?.stdin ?? '{}').env ?? {}) ?? options.redactBy?.[e.argv[4] as string] ?? options.redact ?? [] }), stderr: '' } } - if (bin === python && verb === '-c' && e.argv[2] === RUN_FAILURES) return { value: { ...(options.runFailures ?? { exitCode: 0, stdout: JSON.stringify({ results: [] }) }), stderr: '' } } - if (bin === python && verb === '-c' && options.sliceAnswer) return { value: { ...options.sliceAnswer, stderr: '' } } - if (bin === python && verb === '-c') return { value: { exitCode: 0, stdout: JSON.stringify({ nodes: MANIFEST.nodes, parent_map: MANIFEST.parent_map, child_map: MANIFEST.child_map }), stderr: '' } } - if (bin === python) return { value: { exitCode: 0, stdout: 'Python 3.13.13\n', stderr: '' } } + if (isPython && verb === '-c' && e.argv[2] === PROFILE_REDACT) return { value: { exitCode: 0, stdout: JSON.stringify({ redact: options.redactFrom?.(JSON.parse(e.init?.stdin ?? '{}').env ?? {}) ?? options.redactBy?.[e.argv[4] as string] ?? options.redact ?? [] }), stderr: '' } } + if (isPython && verb === '-c' && e.argv[2] === RUN_FAILURES) return { value: { ...(options.runFailures ?? { exitCode: 0, stdout: JSON.stringify({ results: [] }) }), stderr: '' } } + if (isPython && verb === '-c' && options.sliceAnswer) return { value: { ...options.sliceAnswer, stderr: '' } } + if (isPython && verb === '-c') return { value: { exitCode: 0, stdout: JSON.stringify({ nodes: MANIFEST.nodes, parent_map: MANIFEST.parent_map, child_map: MANIFEST.child_map }), stderr: '' } } + if (bin && verb === '--version' && options.pythonVersions?.[bin]) return { value: { exitCode: 0, stdout: `Python ${options.pythonVersions[bin]}\n`, stderr: '' } } + if (isPython) return { value: { exitCode: 0, stdout: 'Python 3.13.13\n', stderr: '' } } if (e.argv.includes('dbt_map_relations')) { if (!options.mapRelations) return { value: { exitCode: 1, stdout: '', stderr: 'unknown tool: dbt_map_relations' } } mapAsked.push(JSON.parse(String(e.argv[e.argv.indexOf('--args') + 1]))) return { value: { exitCode: 0, stdout: JSON.stringify({ status: 'ok', output: '', metadata: { success: true, mappings: options.mapRelations } }), stderr: '' } } } - if (bin !== (options.pathDbtPython ? 'dbt' : DBT)) return { value: { exitCode: 1, stdout: '', stderr: 'not this test' } } + if (bin !== (options.pathDbtPython ? 'dbt' : DBT) && !options.launchers?.includes(bin as string)) return { value: { exitCode: 1, stdout: '', stderr: 'not this test' } } if (verb === '--version') return { value: { exitCode: 0, stdout: options.version ?? VERSION, stderr: '' } } if (verb === 'debug') { if (options.holdDebug) await options.holdDebug @@ -481,7 +498,7 @@ async function start($: any, on: any, options: Options = {}) { }) await $.session.start({ cwd: ROOT, surface: 'terminal', isInteractive: options.interactive ?? false }) await clock.settle() - return { mapAsked, redactSent, clock, runs, envs, order, cwds, toasts, prompts, store, registered, storeGets, mtimes, opened, sizes, files, setBash: (next: typeof bash) => void (bash = next) } + return { resolved, mapAsked, redactSent, clock, runs, envs, order, cwds, toasts, prompts, store, registered, storeGets, mtimes, opened, sizes, files, setBash: (next: typeof bash) => void (bash = next) } } // ─── What the helpers read from dbt ───────────────────────────────────────────────────────────── @@ -806,6 +823,7 @@ test('a package repo with no manifest of its own: the doctor and model context r target: 'integration_tests/target', files: { 'target/manifest.json': JSON.stringify(borrowed), + 'integration_tests/models/only_in_tests.sql': 'select 1', 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", 'integration_tests/packages.yml': 'packages:\n - local: ../\n', 'integration_tests/dbt_packages/shop/dbt_project.yml': "name: 'shop'\n", @@ -828,6 +846,7 @@ test('a package repo whose manifest comes from integration_tests: the doctor\'s target: 'integration_tests/target', mtimes: { 'models/orders.sql': 5_000 }, files: { + 'target/manifest.json': JSON.stringify(PACKAGE_MANIFEST), 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", 'integration_tests/packages.yml': 'packages:\n - local: ../\n', @@ -871,6 +890,427 @@ test('a package repo with a manifest of its own: the doctor\'s Run dbt parse ref await doctor.unmount() }) +test('a package repo whose target is linked to the one of the project that installs it: the doctor says its packages are installed there, not missing', async ($, on) => { + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + links: { 'target/manifest.json': 'integration_tests/target/manifest.json' }, + files: { + 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + 'integration_tests/dbt_packages/shop/dbt_project.yml': "name: 'shop'\n", + 'target/manifest.json': JSON.stringify(MANIFEST), + 'integration_tests/target/manifest.json': JSON.stringify(MANIFEST), + }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: 'installed in integration_tests, where dbt runs for this package' })).toBeDefined() + expect(await doctor.find({ type: 'Text', text: /packages\.yml is not installed/ })).toBeUndefined() + await doctor.unmount() +}) + +test('a package repo whose target is linked to the one of the project that installs it: the doctor\'s Run dbt parse runs in that project', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + links: { target: 'integration_tests/target' }, + files: { + 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + 'integration_tests/dbt_packages/shop/dbt_project.yml': "name: 'shop'\n", + 'target/manifest.json': JSON.stringify(MANIFEST), + 'integration_tests/target/manifest.json': JSON.stringify(MANIFEST), + }, + }) + await clock.settle() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-parse' }) + await clock.settle() + const at = runs.findIndex(argv => argv[1] === 'parse') + expect(cwds[at]).toBe(`${ROOT}/integration_tests`) + await band.unmount() +}) + +test('a plain project with no package below it: its manifest is its own, the doctor\'s Run dbt parse runs in it', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + files: { + 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', + 'target/manifest.json': JSON.stringify(MANIFEST), + }, + }) + await clock.settle() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-parse' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'parse')]).toBe(ROOT) + await band.unmount() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: /packages\.yml is not installed/ })).toBeDefined() + await doctor.unmount() +}) + +// What dbt writes in the project that installs a package: its own name, and the package's models under the package's. +const PACKAGE_MANIFEST = { ...MANIFEST, metadata: { project_name: 'shop_tests' }, nodes: Object.fromEntries(Object.entries(MANIFEST.nodes).map(([id, node]) => [id, { ...node, package_name: 'shop' }])) } + +const RUNNER_PYTHON = `${ROOT}/integration_tests/.venv/bin/python` +const RUNNER_DBT = `${ROOT}/integration_tests/.venv/bin/dbt` + +const LINKED_REPO = { + 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\nprofile: tests\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + 'integration_tests/dbt_packages/shop/dbt_project.yml': "name: 'shop'\n", + 'integration_tests/profiles.yml': 'tests:\n target: dev\n outputs:\n dev:\n type: duckdb\n', + 'target/manifest.json': JSON.stringify(PACKAGE_MANIFEST), + 'integration_tests/target/manifest.json': JSON.stringify(PACKAGE_MANIFEST), +} + +test('a package repo whose target is linked to the one of the project that installs it: every check of the doctor, its header and what Claude is told are of that project', async ($, on) => { + const { clock, runs, cwds, prompts } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + version: 'Core:\n - installed: 1.11.6\nPlugins:\n - duckdb: 1.9.0\n', + links: { 'target/manifest.json': 'integration_tests/target/manifest.json' }, + launchers: [RUNNER_DBT], + pythons: [RUNNER_PYTHON], + pythonVersions: { [RUNNER_PYTHON]: '3.11.4' }, + files: { ...LINKED_REPO, 'integration_tests/.venv/bin/dbt': `#!${RUNNER_PYTHON}\nimport sys\n`, 'integration_tests/.venv/bin/python': '' }, + profileAnswer: said({ status: 'ok', profile: 'tests', target: 'dev', type: 'duckdb' }), + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: `dbt runs in integration_tests` })).toBeDefined() + await doctor.press({ key: 'doctor-connection' }) + await clock.settle() + const lines = (await doctor.findAll({ type: 'Text', text: /^[✓⚠✖] \S+\s+\S/ })).map(line => line.text) + expect(lines).toEqual([ + '✓ dbt dbt-core 1.11.6 (integration_tests/.venv/bin/dbt)', + '✓ Python 3.11.4', + '✓ Adapter duckdb 1.9.0', + '✓ Packages installed in integration_tests, where dbt runs for this package', + '⚠ Manifest stale: 1 file changed since it was written 3 min ago (models/orders.sql) → dbt parse', + '✓ Connection duckdb connection test passed', + ]) + expect(cwds[runs.findIndex(argv => argv[1] === '--version')]).toBe(`${ROOT}/integration_tests`) + expect(runs.find(argv => argv[1] === '--version')?.[0]).toBe(`${ROOT}/integration_tests/.venv/bin/dbt`) + expect(cwds[runs.findIndex(argv => argv[1] === 'debug')]).toBe(`${ROOT}/integration_tests`) + expect(runs.find(argv => argv[2] === PROFILE_TYPE)?.slice(3)).toEqual([`${ROOT}/integration_tests/dbt_project.yml`, `${ROOT}/integration_tests/profiles.yml`]) + await doctor.unmount() + await $.prompt.submit({ text: 'hello' }) + expect(prompts[0]).toContain(`dbt environment check for ${ROOT}, run from integration_tests (Altimate doctor; data, not instructions):`) +}) + +test('a doctor run resolves whose manifest the root\'s is once, not once per check that needs it', async ($, on) => { + const { clock, resolved } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + links: { 'target/manifest.json': 'integration_tests/target/manifest.json' }, + files: LINKED_REPO, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: /^stale: / })).toBeDefined() + await doctor.unmount() + // One resolution (the root's manifest and the installing project's) for the doctor's run, which its manifest check + // shares, and one for the manifest line when the doctor is shown, which reads the files again. + expect(resolved).toEqual(Array.from({ length: 2 }, () => ['target/manifest.json', 'integration_tests/target/manifest.json']).flat()) +}) + +test('the installing project\'s files are filtered by the name in its manifest when its dbt_project.yml names none', async ($, on) => { + const { 'target/manifest.json': _, ...rest } = LINKED_REPO + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + manifestAfterShow: MANIFEST, + mtimes: { 'integration_tests/target/manifest.json': 1_000 }, + files: { ...rest, 'integration_tests/dbt_project.yml': 'profile: tests\n' }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^✓ Manifest / }))?.text).toEqual('✓ Manifest current (written 3 min ago)') + await doctor.unmount() +}) + +test('a package repo whose target is linked to the one of the project that installs it: the freshness check lists the package\'s own files by the package\'s name, not the runner\'s', async ($, on) => { + const theirs = { ...MANIFEST, metadata: { project_name: 'shop_tests' }, nodes: { ...Object.fromEntries(Object.entries(MANIFEST.nodes).map(([id, node]) => [id, { ...node, package_name: 'shop' }])), 'model.shop.gone': { name: 'gone', resource_type: 'model', package_name: 'shop', original_file_path: 'models/gone.sql', config: {}, columns: {}, depends_on: { nodes: [] } } } } + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + links: { 'target/manifest.json': 'integration_tests/target/manifest.json' }, + files: { ...LINKED_REPO, 'target/manifest.json': JSON.stringify(theirs), 'integration_tests/target/manifest.json': JSON.stringify(theirs) }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: /models\/gone\.sql \(deleted\)/ })).toBeDefined() + await doctor.unmount() +}) + +test('a package repo and its installing project that have no packages installed: the doctor names the installing project\'s packages file, and Run dbt deps runs there', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + manifestAfterShow: MANIFEST, + files: { + 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: 'integration_tests/packages.yml is not installed' })).toBeDefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-deps' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'deps')]).toBe(`${ROOT}/integration_tests`) + await band.unmount() +}) + +test('a package repo with no packages.yml of its own, installed by a project below it that has none installed: the doctor says so, and Run dbt deps runs there', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + manifestAfterShow: MANIFEST, + files: { + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: 'integration_tests/packages.yml is not installed' })).toBeDefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-deps' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'deps')]).toBe(`${ROOT}/integration_tests`) + await band.unmount() +}) + +test('a package repo with its own packages installed, and a manifest only in the project below that lacks them: the doctor works where compile and validate runs, the package itself', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + manifestAfterShow: MANIFEST, + files: { + 'packages.yml': 'packages:\n - package: dbt-labs/dbt_utils\n version: 1.0.0\n', + 'dbt_packages/dbt_utils/dbt_project.yml': "name: 'dbt_utils'\n", + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + 'integration_tests/target/manifest.json': JSON.stringify(MANIFEST), + }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: 'dbt_packages installed' })).toBeDefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-parse' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'parse')]).toBe(ROOT) + await band.unmount() +}) + +test('a package repo and the project that installs it that each have a manifest of their own: the doctor stays in the package, its packages are missing there, and Run dbt parse runs in it', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + files: { ...LINKED_REPO }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: /packages\.yml is not installed/ })).toBeDefined() + expect(await doctor.find({ type: 'Text', text: /dbt runs in/ })).toBeUndefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-parse' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'parse')]).toBe(ROOT) + await band.unmount() +}) + +test('a package repo whose target is linked to the one of the project that installs it: a file changed in that project after the manifest was written makes the manifest stale', async ($, on) => { + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'integration_tests/dbt_project.yml': 5_000 }, + links: { target: 'integration_tests/target' }, + files: LINKED_REPO, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: /stale: 1 file changed .*\(integration_tests\/dbt_project\.yml\)/ })).toBeDefined() + await doctor.unmount() +}) + +test('no manifest anywhere, dbt run in the project that installs the package: the doctor names the manifest a parse there writes', async ($, on) => { + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + manifestAfterShow: MANIFEST, + files: { + 'integration_tests/dbt_project.yml': "name: 'shop_tests'\n", + 'integration_tests/packages.yml': 'packages:\n - local: ../\n', + }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^integration_tests.*is missing/ }))?.text).toEqual('integration_tests/target/manifest.json is missing: lineage, model context and docs need it') + await doctor.unmount() +}) + +test('a package repo whose target is linked to the one of the project that installs it: the doctor reports the Python of that project\'s dbt, not the repo\'s', async ($, on) => { + const { clock, runs } = await start($, on, { + interactive: true, + now: 200_000, + links: { target: 'integration_tests/target' }, + pythonVersions: { [RUNNER_PYTHON]: '3.11.4' }, + files: { ...LINKED_REPO, 'integration_tests/.venv/bin/dbt': `#!${RUNNER_PYTHON}\nimport sys\n`, 'integration_tests/.venv/bin/python': '' }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^✓ Python /u }))?.text).toEqual('✓ Python 3.11.4') + expect(runs.filter(argv => argv[1] === '--version' && argv[0].endsWith('/python')).map(argv => argv[0])).toEqual([RUNNER_PYTHON]) + await doctor.unmount() +}) + +test('a plain project: the doctor reports the Python of the project\'s own dbt', async ($, on) => { + const { clock } = await start($, on, { interactive: true, now: 200_000, pythonVersions: { [`${ROOT}/.venv/bin/python`]: '3.12.1' } }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^✓ Python /u }))?.text).toEqual('✓ Python 3.12.1') + await doctor.unmount() +}) + +// The doctor in a project other than the repo's: its stale files are those of both, each once, newest first. +const STALE_PROJECT = { ...LINKED_REPO, 'dbt_project.yml': "name: 'shop'\nmodel-paths: ['.']\n", 'models/a.sql': 'select 1', 'integration_tests/models/b.sql': 'select 1', 'integration_tests/models/c.sql': 'select 1' } + +test('the doctor in the project that installs a package lists the stale files of both projects once each, newest first', async ($, on) => { + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + links: { target: 'integration_tests/target' }, + mtimes: { 'models/a.sql': 3_000, 'integration_tests/models/b.sql': 4_000, 'integration_tests/models/c.sql': 2_000 }, + files: STALE_PROJECT, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^stale: / }))?.text).toEqual('stale: 3 files changed since it was written 3 min ago (integration_tests/models/b.sql, models/a.sql, integration_tests/models/c.sql)') + await doctor.unmount() +}) + +test('the doctor in the project that installs a package puts a newer file of that project before an older one of the package', async ($, on) => { + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + links: { target: 'integration_tests/target' }, + mtimes: { 'models/a.sql': 3_000, 'integration_tests/models/b.sql': 4_000 }, + files: { ...LINKED_REPO, 'models/a.sql': 'select 1', 'integration_tests/models/b.sql': 'select 1' }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^stale: / }))?.text).toEqual('stale: 2 files changed since it was written 3 min ago (integration_tests/models/b.sql, models/a.sql)') + await doctor.unmount() +}) + +test('a package repo with no manifest of its own, whose own packages are the ones installed: the manifest read is the installing project\'s, so its changed files make it stale', async ($, on) => { + const { 'target/manifest.json': _, 'integration_tests/dbt_packages/shop/dbt_project.yml': __, ...rest } = LINKED_REPO + const { clock } = await start($, on, { + interactive: true, + now: 200_000, + manifestAfterShow: MANIFEST, + mtimes: { 'integration_tests/target/manifest.json': 1_000, 'integration_tests/models/x.sql': 5_000 }, + files: { ...rest, 'dbt_packages/dbt_utils/dbt_project.yml': "name: 'dbt_utils'\n", 'integration_tests/models/x.sql': 'select 1' }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + // dbt runs in the package (its own packages are installed), but the manifest is the installing project's. + expect(await doctor.find({ type: 'Text', text: 'dbt runs in integration_tests' })).toBeUndefined() + expect((await doctor.find({ type: 'Text', text: /^✓ Packages / }))?.text).toEqual('✓ Packages dbt_packages installed') + expect((await doctor.find({ type: 'Text', text: /^stale: / }))?.text).toEqual('stale: 1 file changed since it was written 3 min ago (integration_tests/models/x.sql)') + await doctor.unmount() +}) + +test('a canonical path that cannot be resolved leaves the root\'s manifest the root\'s own: the doctor stays in the package, as it did before paths were resolved', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + links: { target: 'integration_tests/target' }, + statFails: ['target/manifest.json'], + files: LINKED_REPO, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect(await doctor.find({ type: 'Text', text: /dbt runs in/ })).toBeUndefined() + expect(await doctor.find({ type: 'Text', text: /packages\.yml is not installed/ })).toBeDefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-parse' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'parse')]).toBe(ROOT) + await band.unmount() +}) + +test('a target-path that is absolute and linked to the project that installs the package: the doctor works in that project', async ($, on) => { + const { clock, runs, cwds } = await start($, on, { + interactive: true, + now: 200_000, + mtimes: { 'models/orders.sql': 5_000 }, + links: { 'linked-target': 'integration_tests/target' }, + files: { + ...LINKED_REPO, + 'dbt_project.yml': `name: 'shop'\nprofile: 'shop'\ntarget-path: '${ROOT}/linked-target'\n`, + 'linked-target/manifest.json': JSON.stringify(PACKAGE_MANIFEST), + }, + }) + await clock.settle() + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^dbt runs in / }))?.text).toEqual('dbt runs in integration_tests') + expect(await doctor.find({ type: 'Text', text: /packages\.yml is not installed/ })).toBeUndefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-parse' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'parse')]).toBe(`${ROOT}/integration_tests`) + await band.unmount() +}) + +test('a doctor view kept from before it had a place: the pane shows the root alone, and Run dbt deps runs in the root', async ($, on) => { + let kept = false + const legacy = { root: ROOT, checks: [{ id: 'packages', label: 'Packages', status: 'fail', detail: 'packages.yml is not installed', fix: 'dbt deps' }], at: 1, staleFiles: [], busy: null } + on('state.get', async (_: unknown, e: { key: string }, next: (e: unknown) => Promise<{ value?: { value: unknown; version: number } }>) => { + const stored = await next(e) + return kept && e.key === 'dbtDoctor' ? { value: { value: legacy, version: stored.value?.version ?? 0 } } : stored + }) + const { clock, runs, cwds } = await start($, on, { interactive: true, now: 200_000 }) + await clock.settle() + kept = true + const doctor = await $.ui.mount({ ...DOCTOR, surface: 'terminal' }) + expect((await doctor.find({ type: 'Text', text: /^\/proj$/ }))?.text).toEqual(ROOT) + expect(await doctor.find({ type: 'Text', text: /dbt runs in/ })).toBeUndefined() + expect(await doctor.find({ type: 'Text', text: 'packages.yml is not installed' })).toBeDefined() + await doctor.unmount() + const band = await $.ui.mount({ ...BAND, surface: 'terminal' }) + await band.press({ key: 'dbt-doctor-deps' }) + await clock.settle() + expect(cwds[runs.findIndex(argv => argv[1] === 'deps')]).toBe(ROOT) + await band.unmount() +}) + test('a package tested from integration_tests is compiled and validated from there, where its packages are installed', async ($, on) => { const { clock, runs, cwds, toasts } = await start($, on, { pathDbtPython: '/usr/bin/python3', diff --git a/plugins/altimate-code/hooks/dbt-mods.tsx b/plugins/altimate-code/hooks/dbt-mods.tsx index ae5c1209..5c4ebc80 100644 --- a/plugins/altimate-code/hooks/dbt-mods.tsx +++ b/plugins/altimate-code/hooks/dbt-mods.tsx @@ -119,7 +119,7 @@ let seq = 0 let generation = 0 /** Gives Claude the doctor's note with its next prompt, unless the conversation that asked for it has ended. */ function noteDoctor(root: string, view: DoctorView, asked: number) { - if (generation === asked) doctorNoteDue = doctorNote(root, view.checks) + if (generation === asked) doctorNoteDue = doctorNote(root, view.checks, !view.place || view.place === root ? null : relative(root, view.place)) } // Slices of manifests too big to read here, by manifest path, file and revision. const slices = new Map>() @@ -395,6 +395,38 @@ async function runPlaceOf($: EngineInterface, root: string): Promise { return own && own.installed ? root : runner } +/** + * Whether the manifest in `root`'s artifact folder is the project's own: one dbt wrote there, from a parse of the + * project itself. Not when that file is the one of the project below that installs the package (a `target` linked to + * `integration_tests/target`): it is read as the root's, but it is that project's, and the root's packages are not + * what it needs. The doctor's place and its freshness check ask this question. + */ +async function ownManifestOf($: EngineInterface, root: string): Promise { + const own = `${await targetOf($, root)}/manifest.json` + if (!(await $.fs.exists(own).catch(() => false))) return false + const runner = await runnerOf($, root).catch(() => null) + if (!runner) return true + const theirs = `${await targetOf($, runner)}/manifest.json` + const real = (path: string) => $.fs.stat(path, { resolve: true }).then(one => one.realPath ?? path).catch(() => path) + return (await real(own)) !== (await real(theirs)) +} + +/** + * Where the doctor looks at the project: the project itself when it has a manifest of its own, else where compile + * and validate runs dbt. The doctor's dbt, Python, adapter, packages and connection checks, its parse and its deps + * are made there. + */ +async function doctorPlaceOf($: EngineInterface, root: string): Promise { + return (await doctorSiteOf($, root)).place +} + +/** The doctor's place, with whether the root's manifest is its own, resolved once for a caller that needs both. */ +async function doctorSiteOf($: EngineInterface, root: string): Promise<{ place: string; own: boolean }> { + const own = await ownManifestOf($, root) + const runs = await runPlaceOf($, root) + return { place: own ? root : runs, own } +} + /** The project's artifact folder (`target-path` in dbt_project.yml): absolute, or under the project. */ async function targetOf($: EngineInterface, root: string): Promise { const path = targetPath(await $.fs.read(`${root}/dbt_project.yml`).catch(() => '')) @@ -1169,7 +1201,7 @@ const count = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}` const ROOT_CONFIGS = new Set(['dbt_project.yml', 'packages.yml', 'profiles.yml', 'selectors.yml', 'package-lock.yml', 'dependencies.yml']) /** The project's files changed after its manifest was written, newest first. */ -async function changedSince($: EngineInterface, root: string, mtimeMs: number): Promise<{ files: string[]; complete: boolean }> { +async function changedSince($: EngineInterface, root: string, mtimeMs: number, borrowed: boolean, named?: string | null): Promise<{ entries: { path: string; mtimeMs: number }[]; complete: boolean }> { const changed: { path: string; mtimeMs: number }[] = [] let scanned = 0 // A folder that exists but could not be read leaves the answer unknown, never "current". @@ -1186,8 +1218,7 @@ async function changedSince($: EngineInterface, root: string, mtimeMs: number): if (manifest) { // The project's name from the manifest, else dbt_project.yml's (older manifests do not record it). // A package repo's manifest is the project's below it: the package's own files are the ones named by its name. - const borrowed = (await manifestTarget($, root)) !== (await targetOf($, root)) - const project = borrowed ? await projectName($, root) : (manifest.manifest.metadata?.project_name ?? (await projectName($, root))) + const project = borrowed || named ? (named ?? (await projectName($, root))) : (manifest.manifest.metadata?.project_name ?? (await projectName($, root))) const own = (one: any) => !project || !one?.package_name || one.package_name === project const files = (group: any) => Object.values(group ?? {}).filter(own) const disabled = Object.values(manifest.manifest.disabled ?? {}).flat().filter(own) @@ -1244,7 +1275,8 @@ async function changedSince($: EngineInterface, root: string, mtimeMs: number): for (const path of [...new Set(listed)].slice(0, MAX_SCANNED)) { if (!(await $.fs.exists(`${root}/${path}`).catch(() => true))) changed.push({ path: `${path} (deleted)`, mtimeMs: Number.MAX_SAFE_INTEGER }) } - return { files: changed.sort((a, b) => b.mtimeMs - a.mtimeMs).map(one => one.path), complete: complete && scanned <= MAX_SCANNED } + const entries = changed.sort((a, b) => b.mtimeMs - a.mtimeMs) + return { entries, complete: complete && scanned <= MAX_SCANNED } } /** Why the selected output's adapter could not be read. */ @@ -1542,13 +1574,24 @@ async function profileType($: EngineInterface, root: string): Promise { - const target = await manifestTarget($, root) - const stat = await $.fs.stat(`${target}/manifest.json`).catch(() => null) +async function manifestCheck($: EngineInterface, root: string, site?: { place: string; own: boolean }): Promise<{ check: DoctorCheck; staleFiles: string[] }> { + const { place, own } = site ?? (await doctorSiteOf($, root)) + const found = await manifestTarget($, root) + const stat = await $.fs.stat(`${found}/manifest.json`).catch(() => null) + // Missing: the file a parse in the doctor's place writes. + const target = stat || place === root ? found : await targetOf($, place) const shown = target.startsWith(`${root}/`) ? relative(root, target) : target if (!stat) return { check: { id: 'manifest', label: 'Manifest', status: 'warn', detail: `${shown}/manifest.json is missing: lineage, model context and docs need it`, fix: 'dbt parse' }, staleFiles: [] } - const scan = await changedSince($, root, stat.mtimeMs) - const staleFiles = scan.files + const scan = await changedSince($, root, stat.mtimeMs, !own) + // The manifest read is the one of the project below when the root has none of its own: its files are what a + // parse of it reads, wherever the doctor runs dbt. + const owner = own ? null : await runnerOf($, root).catch(() => null) + const there = owner ? await changedSince($, owner, stat.mtimeMs, false, await projectName($, owner)) : null + // A project folder walked from the root holds the other project's files: each counts once, newest first. + const merged = new Map() + for (const one of [...scan.entries, ...(there?.entries ?? []).map(one => ({ ...one, path: `${relative(root, owner!)}/${one.path}` }))]) merged.set(one.path, Math.max(one.mtimeMs, merged.get(one.path) ?? 0)) + const staleFiles = [...merged].sort((a, b) => b[1] - a[1]).map(([path]) => path) + scan.complete = scan.complete && (there?.complete ?? true) const age = Math.round(((await $.clock.now()) - stat.mtimeMs) / 60_000) const ageText = age < 60 ? `${age} min` : age < 2880 ? `${Math.round(age / 60)} h` : `${Math.round(age / 1440)} days` const check: DoctorCheck = staleFiles.length @@ -1599,10 +1642,12 @@ async function doctorNow($: EngineInterface): Promise { async function runDoctor($: EngineInterface, root: string, connection = false): Promise { const previous = await read($, doctorAtom) - await update($, doctorAtom, () => ({ root, checks: previous?.root === root ? previous.checks : [], at: previous?.at ?? 0, staleFiles: previous?.staleFiles ?? [], busy: connection ? 'Testing the connection…' : 'Checking the dbt environment…' })) + await update($, doctorAtom, () => ({ root, place: previous?.root === root ? (previous.place ?? root) : root, checks: previous?.root === root ? previous.checks : [], at: previous?.at ?? 0, staleFiles: previous?.staleFiles ?? [], busy: connection ? 'Testing the connection…' : 'Checking the dbt environment…' })) const checks: DoctorCheck[] = [] - const dbt = await dbtBinary($, root) - const version = await runDbt($, root, ['--version'], 60_000).catch(error => ({ exitCode: -1, stdout: '', stderr: String(error) })) + const site = await doctorSiteOf($, root) + const place = site.place + const dbt = await dbtBinary($, place) + const version = await runDbt($, place, ['--version'], 60_000).catch(error => ({ exitCode: -1, stdout: '', stderr: String(error) })) const info = versionInfo(`${version.stdout}\n${version.stderr}`) if (version.exitCode !== 0 && !info.core) { checks.push({ id: 'dbt', label: 'dbt', status: 'fail', detail: `could not run ${dbt}: ${dbtTail(version, 1)}`.slice(0, 300), fix: 'install dbt-core and your adapter (pip install dbt-core dbt-), or create the project\'s .venv' }) @@ -1623,7 +1668,7 @@ async function runDoctor($: EngineInterface, root: string, connection = false): } // Adapter: the profile's type, installed beside dbt-core. - const type = await profileType($, root) + const type = await profileType($, place) const installed = info.adapters.map(one => one.name) const known = installed.length ? `; installed: ${installed.join(', ')}` : '' if (type && typeof type === 'object') { @@ -1650,35 +1695,33 @@ async function runDoctor($: EngineInterface, root: string, connection = false): checks.push({ id: 'adapter', label: 'Adapter', status: 'ok', detail: `${type}${adapter ? ` ${adapter.version}` : ''}`, fix: null }) } - // Packages: packages.yml with nothing installed (at packages-install-path) fails every parse. A package repo - // whose own packages are not installed is fine when the project below it that installs it (integration_tests) - // has them: dbt is run from there. Not when the package has a manifest of its own: Run dbt parse refreshes that - // one in the package itself, which needs the package's own packages. + // Packages: packages.yml with nothing installed (at packages-install-path) fails every parse. The packages that + // count are those of the doctor's place: a package repo is fine when the project below it that installs it + // (integration_tests) has them, as dbt is run from there, unless the package has a manifest of its own, which + // Run dbt parse refreshes in the package itself. const packages = await packagesOf($, root) - if (packages) { - const ownManifest = await $.fs.exists(`${await targetOf($, root)}/manifest.json`).catch(() => false) - const runner = packages.installed || ownManifest ? null : await runnerOf($, root) - const theirs = runner ? await packagesOf($, runner) : null - const has = packages.installed || (!!runner && (!theirs || theirs.installed)) - const detail = packages.installed ? `${packages.installPath} installed` : has ? `installed in ${relative(root, runner!)}, where dbt runs for this package` : `${packages.file} is not installed` + const theirs = place === root ? null : await packagesOf($, place) + if (packages || theirs) { + const has = place === root ? packages!.installed : !theirs || theirs.installed + const detail = place === root ? (has ? `${packages!.installPath} installed` : `${packages!.file} is not installed`) : has ? `installed in ${relative(root, place)}, where dbt runs for this package` : `${relative(root, place)}/${theirs!.file} is not installed` checks.push({ id: 'packages', label: 'Packages', status: has ? 'ok' : 'fail', detail, fix: has ? null : 'dbt deps' }) } // Manifest freshness. - const manifest = await manifestCheck($, root) + const manifest = await manifestCheck($, root, site) checks.push(manifest.check) const staleFiles = manifest.staleFiles // The connection test opens a warehouse session: only when asked for. if (connection) { - const debug = await runDbt($, root, ['debug', '--log-format', 'text'], 120_000).catch(error => ({ exitCode: -1, stdout: '', stderr: String(error) })) + const debug = await runDbt($, place, ['debug', '--log-format', 'text'], 120_000).catch(error => ({ exitCode: -1, stdout: '', stderr: String(error) })) const parsed = debugInfo(`${debug.stdout}\n${debug.stderr}`) checks.push( debug.exitCode === 0 && parsed.connection !== 'failed' ? { id: 'connection', label: 'Connection', status: 'ok', detail: `${parsed.adapterType ?? (typeof type === 'string' ? type : null) ?? 'warehouse'} connection test passed`, fix: null } : { id: 'connection', label: 'Connection', status: 'fail', detail: (profilesError(`${debug.stdout}\n${debug.stderr}`) ? PROFILES_UNREADABLE : scrubDbt(parsed.detail ?? stripAnsi(debug.stdout || debug.stderr).trim().split('\n').slice(-3).join(' '))).slice(0, 300), fix: 'check profiles.yml credentials; run dbt debug' }, ) - } else if (previous?.root === root) { + } else if (previous?.root === root && (previous.place ?? root) === place) { const kept = previous.checks.find(one => one.id === 'connection') if (kept) checks.push(kept) } @@ -1688,7 +1731,7 @@ async function runDoctor($: EngineInterface, root: string, connection = false): check.detail = redactValues(check.detail) if (check.fix) check.fix = redactValues(check.fix) } - const view: DoctorView = { root, checks, at: await $.clock.now(), staleFiles, busy: null } + const view: DoctorView = { root, place, checks, at: await $.clock.now(), staleFiles, busy: null } // What the pane shows next is read from the files again, not from before this run. manifestRead = null await update($, doctorAtom, () => view) @@ -1699,12 +1742,8 @@ async function parseNow($: EngineInterface, root: string) { const asked = generation const current = await read($, doctorAtom) if (current) await update($, doctorAtom, () => ({ ...current, busy: 'Running dbt parse…' })) - // Where the manifest the doctor and lineage read is written: the project's own when it has one, integration_tests' when - // a package repo borrows that one, else where compile and validate runs dbt (which also notes the runner's package). - const runs = await runPlaceOf($, root) - const own = await targetOf($, root) - const target = await manifestTarget($, root) - const place = target !== own ? ((await runnerOf($, root).catch(() => null)) ?? root) : (await $.fs.exists(`${own}/manifest.json`).catch(() => false)) ? root : runs + // The project's own when it has a manifest of its own, else where compile and validate runs dbt. + const place = await doctorPlaceOf($, root) const run = await runDbt($, place, ['parse', '--log-format', 'text'], 300_000).catch(error => ({ exitCode: -1, stdout: '', stderr: String(error) })) if (run.exitCode !== 0) { const reason = dbtTail({ stdout: run.stdout || run.stderr, stderr: '' }, 3, true, ' ').slice(0, 200) @@ -1844,7 +1883,7 @@ export async function dbtModsBand($: EngineInterface, ui: { Box: any; Button: an {deps ?