Commit Graph

129 Commits

Author SHA1 Message Date
Denis Bilenko 211ec62a70
acc: add Ignore setting to config (#2405)
Ignore output files using gitignore syntax.

## Changes
New Ignore setting in test.toml that will ignore specified files (syntax
is gitignore).

## Why

I'm using it in #2396 to ignore virtual env. It includes a lot of files.
The regular 'rm -fr .venv' approach only works if script get to that
point, but due to errors it might abort early. In that cases test runner
prints all unexpected files, polluting output. Ignoring those files at
test runner level ensure you never see them.

## Tests
Updated selftest/basic.
2025-02-28 14:23:50 +00:00
Andrew Nester 6a07e05e9b
Raise an error when there are multiple local libraries with the same basename used (#2382)
## Changes
It could happen that there are multiple artifacts defined in the bundle
which build and therefore deploy wheel packages with the same name. This
leads to conflict between these packages, they will overwrite each other
and therefore they should have different names instead

Fixes https://github.com/databricks/cli/issues/1674

Previous attempt (https://github.com/databricks/cli/pull/2297 +
https://github.com/databricks/cli/pull/2341) led to the breakage, this
PR fixes both issues.

## Tests
Added acceptance test
2025-02-27 16:32:50 +00:00
shreyas-goenka bc299cafb8
Add warning when variable interpolation is used for auth fields (#2399)
## Changes
This PR adds a warning which gives users clear guidance when they try to
use variable interpolation for an auth field.

## Tests
Modify existing acceptance test.
2025-02-27 15:58:48 +00:00
shreyas-goenka eb57dbd844
Add warning when include is used in config files other than databricks.yml (#2389)
## Changes
Defining an include section in config files other than the main
`databricks.yml` file fails silently. With this PR users will get a
warning when they try this.

## Tests
Acceptance test.
2025-02-27 14:59:00 +00:00
shreyas-goenka bf2aded8e9
Recover from panic gracefully (#2353)
## Changes
This PR adds a recovery function for panics. This indicates to all users
running into a panic that it's a bug and they should report it to
Databricks.

## Tests
Manually and acceptance test.

Before:
```
.venv➜  cli git:(panic-r) ✗ ./cli selftest panic                                                
panic: the databricks selftest panic command always panics

goroutine 1 [running]:
github.com/databricks/cli/cmd/selftest.New.newPanic.func1(0x1400016f208?, {0x1016ca925?, 0x4?, 0x1016ca929?})
        /Users/shreyas.goenka/cli2/cli/cmd/selftest/panic.go:9 +0x2c
github.com/spf13/cobra.(*Command).execute(0x1400016f208, {0x10279bc40, 0x0, 0x0})
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x14000428908)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1050
github.com/databricks/cli/cmd/root.Execute({0x101d60440?, 0x10279bc40?}, 0x10266dd78?)
        /Users/shreyas.goenka/cli2/cli/cmd/root/root.go:101 +0x58
main.main()
        /Users/shreyas.goenka/cli2/cli/main.go:13 +0x44
```

After:
```
.venv➜  cli git:(panic-r) ./cli selftest panic
The Databricks CLI unexpectedly had a fatal error.
Please report this issue to Databricks in the form of a GitHub issue at:
https://github.com/databricks/cli

CLI Version: 0.0.0-dev+aae7ced52d36

Panic Payload: the databricks selftest panic command always panics

Stack Trace:
goroutine 1 [running]:
runtime/debug.Stack()
        /Users/shreyas.goenka/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.darwin-arm64/src/runtime/debug/stack.go:26 +0x64
github.com/databricks/cli/cmd/root.Execute.func1()
        /Users/shreyas.goenka/cli2/cli/cmd/root/root.go:110 +0xa4
panic({0x10368b5e0?, 0x1039d6d70?})
        /Users/shreyas.goenka/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.darwin-arm64/src/runtime/panic.go:785 +0x124
github.com/databricks/cli/cmd/selftest.New.newPanic.func1(0x14000145208?, {0x103356be5?, 0x4?, 0x103356be9?})
        /Users/shreyas.goenka/cli2/cli/cmd/selftest/panic.go:9 +0x2c
github.com/spf13/cobra.(*Command).execute(0x14000145208, {0x104427c40, 0x0, 0x0})
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x14000400c08)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1050
github.com/databricks/cli/cmd/root.Execute({0x1039ec440?, 0x104427c40?}, 0x14000400c08)
        /Users/shreyas.goenka/cli2/cli/cmd/root/root.go:128 +0x94
main.main()
        /Users/shreyas.goenka/cli2/cli/main.go:13 +0x44
```
2025-02-27 13:27:36 +00:00
Denis Bilenko e2db0cd0e2
Remove bundle.{Seq,If,Defer,newPhase,logString}, switch to regular functions (#2390)
## Changes
- Instead of constructing chains of mutators and then executing them,
execute them directly.
- Remove functionality related to chain-building: Seq, If, Defer,
newPhase, logString.
- Phases become functions that apply the changes directly rather than
construct mutator chains that will be called later.
- Add a helper ApplySeq to call multiple mutators, use it where
Apply+Seq were used before.

This is intended to be a refactoring without functional changes, but
there are a few behaviour changes:
- Since defer() is used to call unlock instead of bundle.Defer()
unlocking will now happen even in case of panics.
- In --debug, the phase names are are still logged once before start of
the phase but each entry no longer has 'seq' or phase name in it.
- The message "Deployment complete!" was printed even if
terraform.Apply() mutator had an error. It no longer does that.

## Motivation

The use of the chains was necessary when mutators were returning a list
of other mutators instead of calling them directly. But that has since
been removed, so now the chain machinery have no purpose anymore.

Use of direct functions simplifies the logic and makes bugs more
apparent and easy to fix.

Other improvements that this unlocks:
- Simpler stacktraces/debugging (breakpoints).
- Use of functions with narrowly scoped API: instead of mutators that
receive full bundle config, we can use focused functions that only deal
with sections they care about prepareGitSettings(currentGitSection) ->
updatedGitSection. This makes the data flow more apparent.
- Parallel computations across mutators (within phase): launch
goroutines fetching data from APIs at the beggining, process them once
they are ready.

## Tests
Existing tests.
2025-02-27 11:41:58 +00:00
Denis Bilenko 13ac52391d
acc: Include full output for default-python/classic (#2391)
## Tests
Include full output of default-python/classic so it can be used as a
base for diffs in cloud tests #2383
2025-02-27 10:16:06 +00:00
Denis Bilenko 81606cfcbc
acc: replace LocalOnly option with Local & Cloud (#2387)
## Changes
Instead of LocalOnly with non-composable semantics there are two
composable options:
- Local - enable test locally
- Cloud - enable test on the cloud

By default Cloud is switched off except in bundle (but not in
bundle/variables and bundle/help).

## Tests
Using this in #2383 to have test that runs on cloud but not locally.
2025-02-26 16:01:49 +00:00
Denis Bilenko 6d27c7e69d
acc: Support multiline patterns in diff.py (#2384)
## Changes
Fix diff.py to apply replacements that have newlines in them.

## Tests
Existing tests.
2025-02-26 14:25:39 +01:00
Denis Bilenko 03f2ff5a39
Support serverless mode in default-python template (explicit prompt) (#2377)
## Changes

- Add 'serverless' prompt to default-python template (default is
currently set to "no").
- This is a simplified version of
https://github.com/databricks/cli/pull/2348 with 'auto' functionality
removed.

## Tests
- Split default-python into default-python/classic,
default-python/serverless, default-python/serverless-customcatalog.
- Manually check that "bundle init default-python" with serverless=yes
can be deployed and run on dogfood and test env.
2025-02-26 14:07:30 +01:00
Andrew Nester df001dcdfe
Do not load host from bundle for CLI commands when profile flag is used (#2335)
## Changes
Now when `profile` flag is used we won't pick up host from bundle
anymore and use the one provided by -p flag

Previous behaviour in the context of bundle
```
databricks current-user me -p profile_name
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host https://non-existing-subdomain.databricks.com, but CLI configured to use https://foo.com
```

New behaviour (make an api call)
```
databricks current-user me -p profile_name
{
  email: "foo@bar.com"
  ...
}
```

We still load bundle configuration when `-t` flag provide because we
want to load host information from the target.

Fixes #1358 

## Tests
Added acceptance test
2025-02-26 12:30:38 +00:00
Anton Nekipelov 428e730c9e
Set default data_security_mode to "SINGLE_USER" in bundle templates (#2372)
## Changes
1. Change the **default-python** bundle template to set
`data_security_mode` of a cluster to SINGLE_USER
2. Change the **experimental-jobs-as-code** bundle template to set
`data_security_mode` of a cluster to SINGLE_USER

## Why
Explicitly adding this field saves experienced users from confusion onto
what security mode is applied to the cluster

## Tests
Changed existing unit and integration tests to pass with this change
2025-02-26 13:19:38 +01:00
Andrew Nester fa79d04980
acc: Added tests for deploying PyPi and Maven libraries (#2359)
## Changes
Added PyPi and Maven libraries tests

Needed for this PR since we don't currently have any coverage for PyPi
or Maven libraries
https://github.com/databricks/cli/pull/2382
2025-02-26 13:05:38 +01:00
Andrew Nester cdea775bd2
Fixed spark version check for clusters defined in the same bundle (#2374)
## Changes
Previously using python wheel tasks in the tasks with compute referering
to interactive cluster defied in the same bundle would produce a warning
like below

```
GET /api/2.1/clusters/get?cluster_id=${resources.clusters.development_cluster.id}
< HTTP/2.0 400 Bad Request
< {
<   "error_code": "INVALID_PARAMETER_VALUE",
<   "message": "Cluster ${resources.clusters.development_cluster.id} does not exist"
< } pid=14465 mutator=seq mutator=initialize mutator=seq mutator=PythonWrapperWarning sdk=true
```

This PR fixes it by making sure that we check spark version for such
clusters based on its bundle configuration and don't make API calls

## Tests
Added acceptance test
2025-02-26 13:04:45 +01:00
Andrew Nester 28e094c207
Fixed accessing required path parameters in CLI generation when --json flag (#2373)
## Changes
CLI generation template was using RequiredPathField from incorrect
request entity (body field from request and not request itself). Thus
for some of the commands required path parameters were not required when
--json was specified.

## Tests
Regenerated commands work correctly
2025-02-25 20:20:06 +00:00
Ilya Kuznetsov 25a701be92
Add missing `.gitignore` to dbt-sql and default-sql templates (#2356)
## Changes

Added missing .gitignore files to templates

## Tests

There were some incorrect snapshots of gitignore files in acceptance
tests, probably generated by testing infra. Updated them to new files

---------

Co-authored-by: Lennart Kats (databricks) <lennart.kats@databricks.com>
2025-02-25 09:42:02 +00:00
Denis Bilenko ccdbb1aeba
acc: fix override of settings with null values (#2369)
## Changes
Previously, one could not set `LocalOnly=true` in parent directory and
then override it with `LocalOnly=false` in child directory. This is
because, `false` is considered empty value by mergo.

In order to distinguish between 'explicitly set to false' and 'not set',
I've changed all simple variables in config to be pointers. Now, one can
always override those, because non-nil pointers are not null (with
mergo.WithoutDereference option).

## Tests
Manually:

```
~/work/cli/acceptance/bundle/templates/default-python % cat test.toml   # add this new file 
LocalOnly = false

~/work/cli/acceptance/bundle/templates/default-python % CLOUD_ENV=aws go test ../../.. -run ^TestAccept$/^bundle$/^templates$/^default-python$ -v
(the test is no longer skipped)
```
2025-02-25 08:53:46 +00:00
Denis Bilenko 4881fd873b
acc: Write out.requests.txt immediately (#2368)
## Changes
- Instead of collecting requests in memory and writing them at the end
of the test, write them right away. Then test authors can do filtering
with jq in 'script' or collect individual files per different command.
- testserver is now simpler - it just calls a caller-provided function.
The logging logic is moved to acceptance_test.go.

See https://github.com/databricks/cli/pull/2359/files#r1967591173

## Tests
Existing tests.
2025-02-24 13:37:05 +00:00
Lennart Kats (databricks) f99716b0a5
Remove `run_as` from the built-in templates (#2044)
## Changes

This removes the `run-as` property from the default templates. It's a
useful property but it still only works for jobs and it makes the
default databricks.yml a bit longer. It seems like users can just learn
about it from the docs and/or vary their deployment identity.

Depends on https://github.com/databricks/cli/pull/1712.
2025-02-24 08:31:46 +00:00
Lennart Kats (databricks) bc30d44097
Provide instructions for testing in the default-python template (#2355)
## Changes
Adds instructions for testing to the default-python template.

## Tests
- Unit & acceptance tests.
2025-02-17 12:38:03 +00:00
Denis Bilenko c0a56a93fb
acc: add a helper to diff with replacements (#2352)
## Changes

diff.py is like "diff -r -U2" but it applies replacements first to the
argument.

This allows comparing different output files and directories but ignore
differences that are going to be replaced by placeholders.

This is useful for tests that record large amount of files, specifically
"bundle init" with standard templates. In those tests, changing one
parameter results in a small diff so recording the full directory is not
helpful, because it's hard to see what changed there. I'm using it in
implementation of serverless mode for templates that need it: #2348 The
serverless templates are slightly different from classic, capturing the
diff helps to see exactly where.

Related small changes:
- Add [TESTROOT] replacement for absolute path to acceptance directory
in git repo.
- Add $TESTDIR env var for absolute path to a given test in git repo.

## Tests
- New test acceptance/selftest/diff to test the helper.
- Via #2348 which makes use of this feature.
2025-02-14 11:02:12 +00:00
Denis Bilenko 2d09636611
acc: do not show diff for missing output file (#2350)
It's not interesting since it just dumps what is in the repo. This is
especially annoying with bundle/templates tests with a lot of files.
2025-02-13 07:31:04 +00:00
Denis Bilenko fac9bcf1af
acc: Set X-Databricks-Org-Id on scim/v2/Me endpoint (#2349)
This is needed for b.WorkspaceClient().CurrentWorkspaceID(ctx) which is
used by initialize_urls.go mutator ("bundle summary") #2316

It also also needed for to call serverless detection endpoint #2348

Builds on top of #2338
2025-02-13 07:26:22 +00:00
Pieter Noordhuis 96302c7415
Revert changes related to basename check for local libraries (#2345)
## Changes

These changes break the use of non-local libraries (such as PyPI
libraries).

This reverts the set so we can cut a patch release and take a closer
look later.

Original PRs are #2297 and #2341.

Issue reported in #2343.

## Tests

Manually confirmed that a bundle with PyPI package in libraries now
deploys fine.
2025-02-12 20:05:49 +01:00
Andrew Nester ac439f8c1a
Fix for regression deploying resources with PyPi and Maven library types (#2341)
## Changes

The CheckForSameNameLibraries mutator incorrectly assumed all resource
libraries define libraries as paths of the `string` type, but some
libraries, such as PyPi and Maven, define them as objects.

This PR addresses this issue. It was introduced in #2297.

## Tests

Added regression test.
2025-02-12 17:14:30 +01:00
Denis Bilenko 4034766c93
acc: Simplify writing handlers; support headers in responses (#2338)
## Changes

Handlers now receive testserver.Request and return any which could be
- string or []byte (returns it as is but sets content-type to json or
plain text depending on content)
- struct (encodes it as json and sets content-type to json)
- testserver.Response (full control over status and headers)

Note if testserver.Response is returned from the handler, it's Body
attribute can still be an object. In that case, it'll be serialized and
appropriate content-type header will be added.

The config is now using the same testserver.Response struct, the same
logic applies both configured responses and responses returned from
handlers.

As a result, one can set headers both in Golang handlers and in
test.toml.

This also fixes a bug with RecordRequest not seeing the body if it was
already consumed by the handler.

## Tests
- Existing rests. 
- acceptance/selftest/server is extended to set response header.
2025-02-12 13:00:57 +00:00
Denis Bilenko bfde3585b9
acc: Fix priority of stubs in test.toml (#2339)
## Changes
Reverse the order of stubs to match expectation (leaf configuration
takes precedence over parent configuration).
Follow up to #2334 .

## Tests
acceptance/selftest/server is extended with duplicate handler
2025-02-12 11:45:01 +00:00
shreyas-goenka 24ac8d8d59
Add acceptance tests for auth resolution (#2285)
## Changes

This PR adds acceptance tests for native Databricks auth methods: basic,
oauth, and pat.

In the future we could compare this with auth credentials used by
downstream tools like TF or the telemetry process to ensure consistent
auth credentials are picked up and used.

Note: 
We do not add acceptance tests for other auth methods like Azure because
they communicate with external endpoints. To test them locally, we would
need to set up a reverse proxy server, which is out of scope for this
change.

## Tests
N/A
2025-02-11 15:50:03 +00:00
Denis Bilenko 5d392acbef
acc: Allow mixing custom stubs with default server impl (#2334)
## Changes
- Currently if you define [[Server]] block, you disable the default
server implementation. With this change [[Server]] block takes
precedence over default server but default server remains.
- Switched mux implementation to
[gorilla/mux](https://github.com/gorilla/mux) -- unlike built-in it does
not panic if you set two handlers on the same part (instead the earliest
one wins). It also does not have any dependencies.
- Move acceptance/selftest into acceptance/selftest/basic and added
acceptance/selftest/server that demoes server override.
- Rewrite server set up to ensure that env vars and replacements are set
up correctly. Previously replacements for DATABRICKS_HOST referred to
default server, not to the custom server.
- Avoid calling CurrentUser.Me() in the local case. This allows
overriding /api/2.0/preview/scim/v2/Me, which we use in some tests (e.g.
bundle/templates-machinery/helpers-error). Previously the test passed
because CurrentUser.Me() was calling default server which is incorrect
but it happened to make the tests pass.
- The default server is now available on DATABRICKS_DEFAULT_HOST env
var.
- Rewrite "not found" handler in local test to handle error better (do
not raise http500 when header is already written).

## Tests
New acceptance test selftest/server specifically tests that both custom
and default handlers are available in a single test.
2025-02-11 15:03:41 +00:00
Denis Bilenko 272ce61302
acc: Fix singleTest option to support forward slashes (#2336)
The filtering of tests needs to see forward slashes otherwise it is
OS-dependent.

I've also switched to filepath.ToSlash but it should be a no-op.
2025-02-11 15:26:46 +01:00
Denis Bilenko 8d849fe868
acc: Disable custom server on CLOUD_ENV (#2332)
We're not using local server when CLOUD_ENV is enabled, no need to set
up a custom one.
2025-02-11 10:37:48 +00:00
Denis Bilenko f2096eddcc
acc: Do not show all replacements on every failure (#2331)
## Changes
- Only print replacements if VERBOSE_TEST flag is set.
- This is set on CI but not when you do "go test" or "make test".

Note, env var is used, so that it can be set in Makefile.

## Tests
Manually.
2025-02-11 09:38:53 +00:00
Andrew Nester f7a45d0c7e
Upgrade to TF provider 1.65.1 (#2328)
## Changes
Upgrade to TF provider 1.65.1

Notable changes:
- Now it's possible to use `run_as` field in `pipelines` definition
- Added support for `performance_target` for `jobs`
2025-02-10 14:06:02 +00:00
shreyas-goenka 6953a84db6
Serialize recorded requests with indentation in acceptance tests (#2329)
## Changes
This PR indents the recorded requests to make them easier to review.
They can still be parsed using jq.

## Tests
Existing tests.
2025-02-10 19:03:27 +05:30
Denis Bilenko d282f33a22
Append newline to "-o json" for validate/summary/run (#2326)
## Changes
- Insert newline after rendering indented JSON in bundle
validate/summary/run.
- This prevents "No newline at end of file" message in various cases,
for example when switching between recording raw output of the command
to output processed by jq, since jq does add a newline or when running
diff in acceptance tests.

## Tests
Manually running validate:

```
~/work/dabs_cuj_brickfood % ../cli/cli-main bundle validate -o json | tail -n 2  # without change
Error: root_path must start with '~/' or contain the current username to ensure uniqueness when using 'mode: development'

  }
}%
~/work/dabs_cuj_brickfood % ../cli/cli bundle validate -o json | tail -n 2  # with change
Error: root_path must start with '~/' or contain the current username to ensure uniqueness when using 'mode: development'

  }
}
~/work/dabs_cuj_brickfood %
```

Via #2316 -- see cleaner output there.
2025-02-10 14:00:49 +01:00
shreyas-goenka ee440e65fe
Serialize all header values in acceptance tests (#2311)
## Changes
Based on feedback in
https://github.com/databricks/cli/pull/2296#discussion_r1946660650.
Previously we only serialized the first value for a header in the
requests log. Now we serialise all values for a header key.

## Tests
Existing test
2025-02-10 12:18:05 +00:00
Denis Bilenko 4ebc86282f
acc: Split bundle/templates and bundle/templates-machinery (#2317)
The tests in acceptance/bundle/template focus on standard templates. The
plan is to extend them with "bundle deploy" and enable them on the
cloud.

The tests in acceptance/bundle/template-machinery focus on specific
aspects of template implementation. Most of them are expected to remain
local-only.
2025-02-10 11:55:34 +01:00
Denis Bilenko cc07380185
acc: Summarize unexpected files (#2320)
## Changes
When there are many unexpected files, it's good to see them as a list
rather than scattered throughout the output.

<!-- Summary of your changes that are easy to understand -->

## Tests
Manually, example output:
```
    acceptance_test.go:363: Test produced unexpected files:
        output/my_default_sql/.databricks/bundle/dev/sync-snapshots/71c79ded90615dc7.json
        output/my_default_sql/.databricks/bundle/dev/terraform/.terraform/providers/registry.terraform.io/databricks/databricks/1.64.1/darwin_arm64
        output/my_default_sql/.databricks/bundle/dev/terraform/plan
        output/my_default_sql/.databricks/bundle/prod/sync-snapshots/83e677e75259c93b.json
        output/my_default_sql/.databricks/bundle/prod/terraform/.terraform/providers/registry.terraform.io/databricks/databricks/1.64.1/darwin_arm64
```
2025-02-10 11:53:00 +01:00
Denis Bilenko 2175dd24a4
Do not gitignore .databricks and terraform (#2318)
For acceptance/bundle/templates I'd like to run "bundle deploy". This
would create .databricks directory inside materialized output. It might
makes sense to commit some of this as part of golden files output. Even
if we did not commit anything, the test runner will see those files and
show the difference. Thus git should also see them.

Also rename .gitignore to out.gitignore in those tests, since that
includes .databricks as well.
2025-02-10 11:42:39 +01:00
Andrew Nester f8aaa7fce3
Added support to generate Git based jobs (#2304)
## Changes
This will generate bundle YAML configuration for Git based jobs but
won't download any related files as they are in Git repo.

Fixes #1423 

## Tests
Added unit test

---------

Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
2025-02-07 18:37:03 +00:00
Andrew Nester 2a97dcaa45
Raise an error when there are multiple local libraries with the same basename used (#2297)
## Changes
Raise an error when there are multiple local libraries with the same
basename used

Fixes #1674

## Tests
Added an unit test
2025-02-07 17:55:16 +00:00
Denis Bilenko 6d83ffd109
acc: enable bundle/scripts on cloud (#2313) 2025-02-07 17:42:47 +00:00
Denis Bilenko 989aabe5f1
acc: Make variable tests local-only (#2312)
Makes use of #2294
2025-02-07 17:42:35 +00:00
Denis Bilenko ff4a5c2269
acc: Implement config merge (#2294)
## Changes
Instead of using leaf-most config, all configs from root at
acceptance/test.toml to all intermediate ones to leaf config are merged
into one. Maps are merged, slices are appended, other values are
overridden.

I had to disable caching, because it is tricky when merging is involved
- deep copy is needed. There is performance
impact but currently it is tiny, about 1%.

Also, remove empty root config.

## Tests

Manually checked that inheritance of LocalOnly setting worked for these
tests:

Before - integration tests showed:

```
PASS acceptance.TestAccept/bundle/templates/wrong-url (0.70s)
PASS acceptance.TestAccept/bundle/templates/wrong-path (0.44s)
```

After:

```
SKIP acceptance.TestAccept/bundle/templates/wrong-url (0.00s)
SKIP acceptance.TestAccept/bundle/templates/wrong-path (0.00s)
      acceptance_test.go:216: Disabled via LocalOnly setting in bundle/templates/test.toml, bundle/templates/wrong-path/test.toml (CLOUD_ENV=***)
```
2025-02-07 17:38:27 +01:00
shreyas-goenka f71583fbc0
Error when unknown API endpoint is used in testserver (#2292)
## Changes
This PR fails the acceptance test when an unknown endpoint (i.e. not
stubbed) is used. We want to ensure that all API endpoints used in an
acceptance test are stubbed and do not otherwise silently fail with a
404.

The logs on failure output include a configuration that developers can
simply copy-paste to `test.toml` to stub the missing API endpoint. It'll
look something like:
```
[[Server]]
Pattern = "<method> <path>"
Response.Body = '''
<response body here>
'''
Response.StatusCode = <response status-code here>
```


## Tests
Manually:

output.txt when an endpoint is not found: 
```
>>> [CLI] jobs create --json {"name":"abc"}
Error: No stub found for pattern: POST /api/2.1/jobs/create
```

How this renders in the test logs:
```
    --- FAIL: TestAccept/workspace/jobs/create (0.03s)
        server.go:46: 
            
            ----------------------------------------
            No stub found for pattern: POST /api/2.1/jobs/create
            
            To stub a response for this request, you can add
            the following to test.toml:
            [[Server]]
            Pattern = "POST /api/2.1/jobs/create"
            Response.Body = '''
            <response body here>
            '''
            Response.StatusCode = <response status-code here>
            ----------------------------------------
```

Manually checked that the debug mode still works.
2025-02-07 16:26:48 +00:00
Denis Bilenko 6b1a778fe1
Fix flaky acceptance test (#2310)
## Changes
Replace timestamps with fixed string before output is sorted (and before
test runner replacements are applied).

Otherwise the test sometimes fails with error below. Note, timestamps
themselves do not show it, because they were replaced.

```
    --- FAIL: TestAccept/bundle/debug (0.78s)
        acceptance_test.go:404: Diff:
            --- bundle/debug/out.stderr.parallel.txt
            +++ /var/folders/5y/9kkdnjw91p11vsqwk0cvmk200000gp/T/TestAcceptbundledebug1859985035/001/out.stderr.parallel.txt
            @@ -8,8 +8,8 @@
             10:07:59 Debug: ApplyReadOnly pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync
             10:07:59 Debug: ApplyReadOnly pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:folder_permissions
             10:07:59 Debug: ApplyReadOnly pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:validate_sync_patterns
            -10:07:59 Debug: Path /Workspace/Users/[USERNAME]/.bundle/debug/default/files has type directory (ID: 0) pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync
             10:07:59 Debug: non-retriable error:  pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
            +10:07:59 Debug: Path /Workspace/Users/[USERNAME]/.bundle/debug/default/files has type directory (ID: 0) pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync
             < {} pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
             < {} pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
             < } pid=12345 mutator=validate mutator (read-only)=parallel mutator (read-only)=validate:files_to_sync sdk=true
```

## Tests
Running `hyperfine --min-runs 10 'go test ../.. -run
^TestAccept$/^bundle$/^debug$ -count=1' --show-output` detects flakiness
on main but not with this PR.
2025-02-07 16:17:50 +00:00
Denis Bilenko ecc05689ca
Add a couple of tests for bundle init with custom template (#2293)
These test custom template and what happens if helper function returns
an error.
2025-02-07 13:13:12 +00:00
Denis Bilenko 54e16d5f62
Always print warnings and errors; clean up format (#2213)
## Changes
- Print warnings and errors by default.
- Fix ErrAlreadyPrinted not to be logged at Error level.
- Format log messages as "Warn: message" instead of "WARN" to make it
more readable and in-line with the rest of the output.
- Only print attributes (pid, mutator, etc) and time when the overall
level is debug (so --debug output has not changed much).

## Tests
- Existing acceptance tests show how warning messages appear in various
test case.
- Added new test for `--debug` output.
- Add sort_lines.py helper to avoid dependency on 'sort' which is
locale-sensitive.
2025-02-07 11:29:40 +00:00
Gleb Kanterov 75127fe42e
Extend testserver for deployment (#2299)
## Changes
Extend testserver for bundle deployment:

- Allocate a new workspace per test case to isolate test cases from each
other
- Support jobs get/list/create
- Support creation and listing of workspace files

## Tests
Using existing acceptance tests
2025-02-07 10:26:20 +00:00
Andrew Nester 5c90752797
acc: Added acceptance test for CLI commands inside bundle with and without profile flag (#2270)
## Changes
This encodes existing behaviour in CLI as reported here: #1358
2025-02-05 11:53:36 +00:00