Skip to content

testserver: convert notebook formats on workspace export, match import errors - #8060

Merged
denik merged 4 commits into
mainfrom
denik/intdep-workspace-testserver
Nov 30, 2026
Merged

denik merged 4 commits into
mainfrom
denik/intdep-workspace-testserver

Conversation

@denik

@denik denik commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Changes

libs/testserver stored a notebook in the format it was imported in and returned it unchanged on export. The real /api/2.0/workspace/export converts. 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 .ipynb returns source: the header line, cells separated by COMMAND ---------- lines, and markdown cells and magic-command cells (%sql, ...) as MAGIC lines.
  • format=JUPYTER of a source notebook returns ipynb: one cell per COMMAND block, and MAGIC %md blocks become markdown cells. Of an ipynb notebook, it returns the notebook with language_info.name in lower case.
  • format=SOURCE of a source notebook imported without the header line adds the header line.
  • format=JUPYTER of a file returns 400 Exporting a FILE asset at <path> in JUPYTER format is not supported.

Import (handlers.go, fake_workspace.go):

  • format=SOURCE without a language (which is what databricks workspace import X --file Y sends with neither --language nor --format) returns 400 The 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.
  • A notebook import over an existing object without overwrite is rejected on every route (/workspace/import SOURCE, JUPYTER and AUTO, legacy import-file, zip entries). Before, AUTO and import-file overwrote silently, so workspace import-dir without --overwrite replaced existing notebooks locally. The check now lives in storeNotebook. The messages are the recorded ones:
    • /workspace/import: <notebook> already exists. Please pass overwrite=true to overwrite it.
    • import-file: Request failed for POST <path>: RESOURCE_ALREADY_EXISTS: <notebook> already exists. ...
  • format=JUPYTER with a body that is not a Jupyter notebook returns an explicit "not supported" 500 instead of storing it.
  • A Jupyter notebook's object info (get-status, list) reports PYTHON whatever 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 example SQL) in the object info. The new Cloud = true test acceptance/cmd/workspace/import-jupyter-language records 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, see integration/README.md) to a Cloud = true acceptance test. These behaviors are what its local run needs to produce the same output as the cloud run.

Tests

  • New unit tests in 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. TestWorkspaceImportFileJupyter used to assert SQL for a notebook with Databricks SQL metadata; it now asserts PYTHON, which is what AWS returned for that notebook.
  • The full local acceptance suite passes with no golden changes.
  • The cloud pin for these responses is the stacked acceptance test. Its output.txt is identical locally and on AWS.

Judgment calls and limits (not modeled, unchanged from before):

  • a directory at a notebook's path, and overwrite=true replacing a FILE with a NOTEBOOK
  • format=JUPYTER export of a directory
  • formats other than SOURCE and JUPYTER, and cell metadata and outputs
  • The stored format is detected from the body. A SOURCE notebook whose text is itself a valid ipynb document exports as if it were Jupyter. Recording the import format on FileEntry would 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.

…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>
@github-actions github-actions Bot added the test-only-fix PRs that update failing of flaky tests without changing CLI code. label Nov 26, 2026
@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 8bdd1c2

Run: 46401743288

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 174 17 2:46
💚​ aws-windows-latest-4core-16gb 1 174 17 4:03
💚​ azure linux-2core-8gb 1 173 17 3:02
💚​ azure-windows-latest-4core-16gb 1 173 17 4:15
💚​ gcp linux-2core-8gb 1 174 17 2:41
💚​ gcp-windows-latest-4core-16gb 1 174 17 3:59
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:21 azure-windows-latest-4core-16gb TestAccept
3:06 aws-windows-latest-4core-16gb TestAccept
3:00 gcp-windows-latest-4core-16gb TestAccept

@denik
denik marked this pull request as ready for review November 26, 2026 14:57
@denik
denik requested a review from a team as a code owner November 26, 2026 14:57

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread libs/testserver/workspace_export.go Resolved
Comment thread libs/testserver/workspace_export.go Resolved
Comment thread libs/testserver/workspace_export.go Resolved
Comment thread libs/testserver/workspace_export.go Resolved
Comment thread libs/testserver/fake_workspace.go Resolved
…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>
@denik

denik commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

🤖 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>
@denik

denik commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Pushed da07ec6: on AWS, imported Jupyter notebooks report language PYTHON in their object info whatever the kernel or Databricks metadata says, while their exports use the content language (language_info.name, else Databricks metadata, else Python). The fake reported the metadata language. Fixed, with unit tests that fail without the fix, and a new Cloud = true test, acceptance/cmd/workspace/import-jupyter-language, whose local output is identical to the AWS recording. #8066 is rebased on top. AI agent (opus5.5, isaac_claude)

@denik
denik requested a review from andrewnester November 26, 2026 23:59
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: 8bdd1c2f8 | Workflow run

Selected 1 changed tests (limit=20, 0 not selected)

1 tests: regression=0 unreleased=0 coverage=1 failing=0
test branch main (9a14ad6) latest (v1.28.0)
TestAccept/cmd/workspace/import-jupyter-language ✅ ✅ ✅

@denik
denik enabled auto-merge November 30, 2026 10:37
@denik
denik added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 18fb21e Nov 30, 2026
27 checks passed
@denik
denik deleted the denik/intdep-workspace-testserver branch November 30, 2026 11:06
stevenayers pushed a commit to stevenayers/cli that referenced this pull request Nov 30, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

factory-generated test-only-fix PRs that update failing of flaky tests without changing CLI code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants