Repository navigation
testserver: convert notebook formats on workspace export, match import errors - #8060
Conversation
…t errors The fake workspace returned a notebook in the format it was imported in, while the real /workspace/export converts it: SOURCE for a notebook imported from .ipynb (header line, COMMAND separators, MAGIC lines for markdown and magic cells), JUPYTER for a source notebook, with the header line added on SOURCE. It also accepted what the real API rejects: a SOURCE import without a language (the real API reads it as a zip archive), a JUPYTER export of a file, and a notebook import over an existing notebook without overwrite. A notebook without language metadata is stored as Python, and / can be listed. The expected responses are the ones the real API returned on AWS. Co-authored-by: Isaac <no-reply@databricks.com>
✅ Integration test reportCommit: 8bdd1c2
Top 3 slowest tests (at least 2 minutes):
|
There was a problem hiding this comment.
Automated review at 2001c27. Each finding was verified against the code.
No blocking issues found. 5 non-blocking comment(s) below.
This PR teaches the test server's /workspace/export to convert between SOURCE and Jupyter, and brings several import paths in line with recorded real-API responses: SOURCE without a language, collisions without overwrite, invalid JUPYTER bodies, and listing the root. The import and collision changes look right. Three things in the new converter can still give output that differs from a cloud run: exports guess the notebook's format from its bytes, blank lines in MAGIC cells come out wrong, and export formats the converter doesn't model are silently ignored. The rest are comment fixes.
…ook exports An empty line of a markdown or magic cell exports as "# MAGIC" without a trailing space, as recorded on AWS. HTML, DBC and R_MARKDOWN exports of a notebook return an explicit "not supported" 500 instead of the stored body. Comments now say the existence check covers files and notebooks. Co-authored-by: Isaac <no-reply@databricks.com>
|
🤖 Addressed all 5 comments of the automated review in d1bbc85 (3 fixed, plus 2 comment fixes; the format-sniffing residual stays a documented judgment call). Full local acceptance and the testserver unit tests pass. AI agent (opus5.5, isaac_claude) |
…heir content language On AWS, the object info of a notebook imported from .ipynb (format=JUPYTER or import-file) reports language PYTHON whatever its metadata says. The exports use the content language instead: language_info.name, else the Databricks metadata language, else Python. That language sets the SOURCE comment syntax and the JUPYTER language metadata. The fake reported the metadata language in the object info and used it for exports. acceptance/cmd/workspace/import-jupyter-language records this on cloud for R, Scala, SQL and Python kernels and for Databricks metadata, through both import routes. cloud: TestAccept/cmd/workspace/import-jupyter-language Co-authored-by: Isaac <no-reply@databricks.com>
|
🤖 Pushed da07ec6: on AWS, imported Jupyter notebooks report language |
Regression test report ✅Commit: Selected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=0 unreleased=0 coverage=1 failing=0
|
…ivalents (databricks#8066) Stacked on databricks#8060 (testserver: notebook export conversions and import errors). Review that one first; this PR's diff is against its branch. ## Changes Delete `integration/cmd/workspace` (14 tests and their testdata). Add one acceptance test that covers all of them: `acceptance/cmd/workspace/import-export`. It is `Cloud = true` with no `CloudEnvs`, so it runs locally against the testserver and on every cloud. It reuses the integration tests' `import_dir` fixtures byte for byte. I added a new directory rather than extending one, because the nearest siblings (`export-dir-*`) are local-only stubs or dashboard-specific. | deleted integration test | verdict | covered by | |---|---|---| | TestWorkspaceList | PORTED | import-export: `workspace list /` header, empty stderr | | TestWorkpaceExportPrintsContents | PORTED | import-export: export to stdout is byte-identical, empty stderr | | TestExport | PORTED | import-export: file and notebook export are byte-identical, `--format JUPYTER` has `cells`/`metadata` | | TestExportWithFileFlag | PORTED | import-export: `--file` for file, notebook, JUPYTER; empty stdout | | TestExportDir | PORTED | import-export: export-dir log lines, contents per language, header-only notebooks, empty stderr | | TestExportDirDoesNotOverwrite | PORTED | import-export: `(skipped; already exists)`, local file kept | | TestExportDirWithOverwriteFlag | PORTED | import-export: `--overwrite` replaces the local file | | TestImportDir | PORTED | import-export: import-dir log lines, type, language and content of all 7 objects (incl. `.ipynb`), empty stderr with `--log-level=debug` | | TestImportDirDoesNotOverwrite | PORTED | import-export: seeds read back, skips, all 7 objects read after | | TestImportDirWithOverwriteFlag | PORTED | import-export: seeds read back, replaced, all 7 objects read after | | TestImportFileUsingContentFormatSource | PORTED | import-export: `--content` + `--language` creates notebooks | | TestImportFileUsingContentFormatAuto | PORTED | import-export: AUTO file vs notebook by extension and content | | TestImportFileFormatSource | PORTED | import-export: `--file` + `--language`; without either, `The zip archive contains no items.` | | TestImportFileFormatAuto | PORTED | import-export: `--file` AUTO file vs notebook | ## Why `integration/` is deprecated (see `integration/README.md` and `.agents/rules/testing.md`). Acceptance tests with `Cloud = true` keep the cloud check and also run locally on every PR. Earlier batches: databricks#6113, databricks#6140, databricks#6223, databricks#6316, databricks#7251. ## Coverage proof Method: - Blocks: each integration test was run alone on AWS with `-coverpkg=github.com/databricks/cli/...`. Its blocks were compared with the per-test coverage of a full local acceptance run plus an AWS run of the new test. - Assertions: every assertion of the deleted tests is mapped to a line of the new test's output (details below). | integration test | verdict | product blocks | covered | acceptance tests (minimal set) | |---|---|---|---|---| | TestExport | PORTED | 1023 | all but 3 | bundle/run/app-with-job, cmd/aitools/telemetry/hint (+ import-export for the assertions) | | TestExportDir | PORTED | 986 | all but 3 | cmd/workspace/import-export, bundle/resources/job_runs/wait, cmd/aitools/telemetry/hint | | TestExportDirDoesNotOverwrite | PORTED | 963 | all but 3 | cmd/workspace/import-export, bundle/resources/job_runs/wait, cmd/aitools/telemetry/hint | | TestExportDirWithOverwriteFlag | PORTED | 972 | all but 3 | cmd/workspace/import-export, bundle/resources/job_runs/wait, cmd/aitools/telemetry/hint | | TestExportWithFileFlag | PORTED | 899 | all but 3 | bundle/sync/zip-extract, cmd/workspace/import-export, cmd/aitools/telemetry/hint | | TestImportDir | PORTED | 1040 | all but 3 | cmd/workspace/import-export, bundle/resources/job_runs/wait, cmd/aitools/telemetry/hint | | TestImportDirDoesNotOverwrite | PORTED | 1002 | all but 3 | cmd/workspace/import-export, bundle/resources/job_runs/wait, cmd/aitools/telemetry/hint | | TestImportDirWithOverwriteFlag | PORTED | 992 | all but 3 | cmd/workspace/import-export, bundle/resources/job_runs/wait, cmd/aitools/telemetry/hint | | TestImportFileFormatAuto | PORTED | 915 | all but 3 | bundle/invariant/migrate, cmd/aitools/telemetry/hint, cmd/workspace/import-export | | TestImportFileFormatSource | PORTED | 945 | all but 3 | bundle/generate/auto-bind, cmd/workspace/import-export, cmd/aitools/telemetry/hint | | TestImportFileUsingContentFormatAuto | PORTED | 913 | all but 3 | bundle/invariant/migrate, cmd/aitools/telemetry/hint, cmd/workspace/import-export | | TestImportFileUsingContentFormatSource | PORTED | 913 | all but 3 | bundle/invariant/migrate, cmd/aitools/telemetry/hint, cmd/workspace/import-export | | TestWorkpaceExportPrintsContents | PORTED | 920 | all but 3 | bundle/sync/zip-extract, cmd/aitools/telemetry/hint (+ import-export for the assertions) | | TestWorkspaceList | PORTED | 894 | all but 3 | cmd/workspace/import-export, cmd/aitools/telemetry/hint, cmd/sync/upload-504 | ("product blocks" counts the raw blocks, harness blocks included. "all but 3" means every block except harness code and the 3 blocks below.) Uncovered blocks: the same 3 in every test. All of them are reached only by the in-process test harness: - `cmd/root/auth.go:222.3,223.1`: the `factory == nil` return in `bindHostMetadataLogger`. Only `main.go` registers the factory, so only in-process test binaries (`internal/testcli`) take this branch. Acceptance tests run the built CLI. - `cmd/root/tree.go:54` and `:57`: `Tree.SetOut` and `Tree.SetErr`. Only `internal/testcli/runner.go` calls them, to capture output in-process. <details> <summary>Assertion map</summary> | integration test | fact | acceptance check | where | |---|---|---|---| | TestWorkspaceList | `list /` succeeds, header ID/Type/Language/Path, stderr empty | `ID Type Language Path`, `assert_empty` | local + cloud | | TestWorkpaceExportPrintsContents | export prints the file byte for byte, stderr empty | `cmp fixtures/script.sh`, `assert_empty` | local + cloud | | TestExport | file `abc` exact; notebook `# Databricks notebook source\n` exact; JUPYTER has cells/metadata | `cmp` x2, `{"has_cells":true,"has_metadata":true}` | local + cloud | | TestExportWithFileFlag | `--file` writes content, stdout empty (file, notebook, JUPYTER) | `assert_empty` on stdout, `cmp`, jq | local + cloud | | TestExportDir | log lines in order, notebook extensions, contents, header-only notebooks, stderr empty | export-dir block, `cat` of each file, `cmp` of header-only fixtures | local + cloud | | TestExportDirDoesNotOverwrite / WithOverwriteFlag | local file kept / replaced | `(skipped; already exists)` + `local content`; `cmp fixtures/file-a` | local + cloud | | TestImportDir | log lines, contents of all objects incl. `.ipynb` as source, stderr empty with debug logging | import-dir block, `show` of 7 objects, debug log to `--log-file`, `assert_empty` | local + cloud | | TestImportDirDoesNotOverwrite / WithOverwriteFlag | seeds present before; others imported; seeds kept / replaced | `show` before and after for all 7 objects | local + cloud | | TestImportFileUsingContent* / TestImportFileFormat* | notebook vs file by `--language`, AUTO, extension and content; zip error | `show` (type, language, content), `musterr` + error text | local + cloud | | cleanup | test dir removed | `workspace delete --recursive`, then `musterr workspace get-status` | local + cloud | The deleted TestImportDir asserted empty stderr with `--log-level=debug`. That only held because the in-process harness captured the command's stderr writer, while logs go to the process's `os.Stderr`. The new test sends the debug log to `--log-file` and asserts the command's stderr is empty. </details> Runtime: the 14 integration tests took about 65 s of test time on AWS. The new acceptance test takes 84 s on AWS (local run) and about 1 s locally. In this PR's cloud CI it takes about 2 min on Linux and 2.5 min on Windows. Judgment calls: - Windows: the test runs on Windows with a `\\` -> `/` replacement for the local paths that export-dir and import-dir print. - Cloud: the integration tests have no per-cloud branches. This PR's cloud CI (`cloud:` line in the last commit) ran the test on AWS, Azure and GCP, on Linux and Windows, and it passed everywhere. - Mutation check: making export-dir or import-dir ignore `--overwrite` fails the test. Dashboard: none (the deleted tests were not failing). This PR was created by the integration-deprecation loop. 🤖 AI agent (opus5.5, isaac_claude) This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
Changes
libs/testserverstored a notebook in the format it was imported in and returned it unchanged on export. The real/api/2.0/workspace/exportconverts. The fake also accepted several imports the real API rejects. This PR makes the fake match the real API on these paths. Every expected response below was recorded against a real AWS workspace.Export (
libs/testserver/workspace_export.go, new):format=SOURCE(or no format) of a notebook imported from.ipynbreturns source: the header line, cells separated byCOMMAND ----------lines, and markdown cells and magic-command cells (%sql, ...) asMAGIClines.format=JUPYTERof a source notebook returns ipynb: one cell perCOMMANDblock, andMAGIC %mdblocks become markdown cells. Of an ipynb notebook, it returns the notebook withlanguage_info.namein lower case.format=SOURCEof a source notebook imported without the header line adds the header line.format=JUPYTERof a file returns 400Exporting a FILE asset at <path> in JUPYTER format is not supported.Import (
handlers.go,fake_workspace.go):format=SOURCEwithout a language (which is whatdatabricks workspace import X --file Ysends with neither--languagenor--format) returns 400The zip archive contains no items.The real API reads such content as a zip archive of notebooks. A non-empty zip returns an explicit "not supported" 500, since extracting archives is not modeled./workspace/importSOURCE, JUPYTER and AUTO, legacy import-file, zip entries). Before, AUTO and import-file overwrote silently, soworkspace import-dirwithout--overwritereplaced existing notebooks locally. The check now lives instoreNotebook. The messages are the recorded ones:/workspace/import:<notebook> already exists. Please pass overwrite=true to overwrite it.Request failed for POST <path>: RESOURCE_ALREADY_EXISTS: <notebook> already exists. ...format=JUPYTERwith a body that is not a Jupyter notebook returns an explicit "not supported" 500 instead of storing it.PYTHONwhatever its metadata says, on both the JUPYTER import and import-file. Its exports use the content language instead:language_info.name, else the Databricks metadata language, else Python. That language sets the SOURCE comment syntax and the JUPYTER language metadata. Before, the fake reported the metadata language (for exampleSQL) in the object info. The newCloud = truetestacceptance/cmd/workspace/import-jupyter-languagerecords this for R, Scala, SQL and Python kernels and for Databricks metadata, through both routes.GET /workspace/list?path=/lists the root instead of returning 404.Why
The next PR in this stack (#8066) moves
integration/cmd/workspace(14 tests, deprecated tree, seeintegration/README.md) to aCloud = trueacceptance test. These behaviors are what its local run needs to produce the same output as the cloud run.Tests
libs/testserver/workspace_test.go. Each one fails without the change (checked by reverting the production files).acceptance/cmd/workspace/import-jupyter-language(Cloud = true): its output is identical locally and on AWS.TestWorkspaceImportFileJupyterused to assertSQLfor a notebook with Databricks SQL metadata; it now assertsPYTHON, which is what AWS returned for that notebook.output.txtis identical locally and on AWS.Judgment calls and limits (not modeled, unchanged from before):
overwrite=truereplacing a FILE with a NOTEBOOKformat=JUPYTERexport of a directoryFileEntrywould touch shared state that Let each fake API in the test server own its state #8018 rewrites.Dashboard: none (no failing test; prerequisite for the integration test port).
This PR was created by the integration-deprecation loop.
🤖 AI agent (opus5.5, isaac_claude)
This pull request and its description were written by Isaac.