453 Commits
Author SHA1 Message Date
Julio López 9025d496cf fix(testing): TestServerControlSocketActivated flake (#5643)
Fix TestServerControlSocketActivated flake.
- Clear `runner.ExtraFiles` before calling running other
  commands. This appears to be the primary source of
  the spurious test failures.

Refactor `TestServerControlSocketActivated` to:
- start server from the test (go)routine instead of a background one;
- process server's output synchrounously in the test goroutine;
- fix race: close the listener file descriptor synchronously in the
  test goroutine instead of async, which ensures the descriptor is
  closed before sending the first request to the (status) server;
  otherwise, shutdown hangs (when the listener close is delayed);
- check and assert server's exit status;
- improve test cleanup: ensure child server process terminates
  and is reaped on assertion failure.

Also, address potential race in `TestServerControlSocketActivatedTooManyFDs`
check with explanation comment. There is still a posible race where
the stderr pipe is closed before the background async callback gets
the error message. This will be addressed separately.
2026-09-13 20:21:44 -07:00
Julio López fdf0159a17 refactor(general): cleanup various nits (#5618)
- use struct field initialization idiom
- clarify error message
- directly use s.rootctx in server request processing
- refactor: use require in e2e ACL test
- inline constant definition
- modernize with `strings.Cut`
- modernize with slices.Backward
- simplify timeFormat initialization
- refactor testing: check `Scanner.Err()` in testenv
- remove spurious parenthesis
- trueStr and falseStr consts
- use inheritPolicyString
- use const in cache info
- "bytes" const in ui task counters
- use common consts in gettool
2026-09-06 15:08:49 -07:00
Julio López 9473eef9d1 build(deps-dev): upgrade golangci-lint to v2.11.4 (#5247)
Fixes for new linter warnings:
- fix: add //nolint annotations where it makes sense
- fix: remove no-longer necessary linter annotations
- fix linter: add or remove new lines
- fix linter: use Fprintf instead of WriteString
- fix: check for overflow in conversion to uint8 / byte
2026-09-03 12:12:20 -07:00
Julio López 116ec249c2 chore(general): remove unused deprecated field (#5476)
- remove unused field `encryptorInfo.deprecated`
- simplify implementations and function signatures
- deprecate `--deprecated` CLI flag
2026-07-06 21:59:15 -07:00
Julio López 93b5d82c41 refactor(testing): reduce spurious failures in TestPickWeighted (#5446)
Increase error tolerance for resulting weights in
TestPickWeighted to reduce spurious failures.
The test is non-deterministic by nature.

Refactor:
- run test cases in sub-tests
- make constant more legible
- use require
2026-06-23 17:56:15 -07:00
c26c6a1b97 feat(cli): restrict insecure unauthenticated server to loopback binds (#5354)
* feat(cli): restrict insecure unauthenticated server to loopback binds

Reject starting the server with --insecure and --without-password when
--address would bind outside loopback (including empty host / all
interfaces). Validate the actual listener after Listen so systemd socket
activation cannot bypass the check.

Add hidden --allow-extremely-dangerous-unauthenticated-server-on-the-network
to opt into the previous behavior for isolated environments.

Extract validation into internal/insecureserverbind with table-driven tests.
Add end-to-end smoke tests for rejection and escape hatch.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Update internal/insecureserverbind/insecureserverbind.go

Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>

* pr feedback

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Julio López <1953782+julio-lopez@users.noreply.github.com>
2026-05-04 19:51:20 -07:00
Julio López d1e5c1d8a0 chore(general): clean nits (#5313)
- make benchmarking params uint
- prevent error in compression benchmarking
- lint on Windows and address linter warnings
- upgrade golang.org/x/exp
- upgrade github.com/cncf/xds/go
- upgrade github.com/dustinkirkland/golang-petname
- direct users to forum
- add warning about _recovery recipes_
2026-04-16 21:41:39 -07:00
Julio López 67f26feb93 test(kopiaui): skip htmlui tests that are timing out (#5257)
This appears to be caused by changes in the Chrome
version that is included in the updated runner image.
2026-03-31 12:16:08 -07:00
Julio LópezandGeoffrey D. Bennett 4fe60817a0 fix(snapshots): inaccessible entry causes parent directory to be skipped (#5217)
Revert "feat(snapshots): localfs support for passing options (#5044)"
commit c8c4615595.

Fix: return `ErrorEntry` for permission denied instead of aborting

When iterating a directory, if `lstat` fails with permission denied on
an entry, return an `ErrorEntry` instead of an error that stops the
entire directory iteration.

Previously, a single inaccessible entry, such as, a FUSE/sshfs mount
owned by another user, would cause the entire containing directory to
fail and be omitted from the snapshot, resulting in data loss.

Now, the inaccessible entry is returned as an ErrorEntry which is
handled according to the configured error handling policy, allowing
iteration to continue and the rest of the directory to be backed up.

- Fixes: #5045

Differentiate entry type when ignoring failed entries
Fix tests for new behavior, including handling timing-dependent
behavior when snapshots --fail-fast

---------

Co-authored-by: Geoffrey D. Bennett <g@netcraft.com.au>
2026-03-19 12:24:38 -07:00
Julio López 3ea28b4af3 refactor(testing): nits in TestSnapFail tests (#5228)
* rename loop var for clarity
* only log on error
* rename var for clarity
* use t.Cleanup
* save environment once for all subtests
* get perms for modified entry once
* move repo setup to testPermissions
* create empty dir<maxDirDepth> so there are 3 entries in dir<maxDirDepth-1>
2026-03-18 20:52:31 -07:00
Julio López 38fb7ef699 refactor(testing): TestSnapshotFail* (#5225)
- leverage require
- remove unused return value
- remove unnecessary intermediate vars
- rename variable to maxDirDepth for clarity
- limit test file sizes
- improve to readability
- improve sub-test naming format
- run each file mode case in a sub-test
- move test case to separate function
- move long loop block to separate function
- run loop iterations in sub-tests
- rename test params for consistency
- add t.Helper()
- coarser-grained parallelism
- restore each snapshot into a separate directory
- update function comment
2026-03-17 22:12:00 -07:00
Julio López 873a89a08d refactor(general): move SafeLongFilename to ospath (#5227)
- Move MaybePrefixLongFilenameOnWindows to ospath package and rename
  it to SafeLongFilename, along with corresponding test.
- Elide the function implementation at build time on non-Windows
  platforms.
- Update documentation and comments for clarity.
- Rename package-local helper function.
2026-03-17 17:43:08 -07:00
Julio López 39fb62970f refactor(cli): refactor diagnosis flags (#5026)
Refactor `--profile-*` flags:
- Multiple profile types can be enabled at once, before only
  a single type profiling could be done during a process execution.
- The new `--profiles-store-on-exit` enables all available profile
  types, except for CPU profiling which needs to be explicitly enabled.
- Profiling parameters can now be set via new flags. This allows setting
  the profile parameters for the pprof endpoint, as well as when saving
  profiles to files on exit.
- Group profiling flags with other observability flags
- Adds a `--diagnostics-output-directory` flag that unifies and
  supersedes the `--profile-dir` and `--metrics-directory` flags

Enhancements and behavior changes:
- Profile flags now have effect for all kopia commands, including
  `server start`. Before these flags did not have any effect
  in a few commands.
- Multiple profile types can be enabled at once, before only
  a single type profiling could be done during a process execution.
- The new `--profiles-store-on-exit` enables all available profile
  types, except for CPU profiling which needs to be explicitly enabled.
- Profiling parameters can now be set via new flags. This allows setting
  the profile parameters for the pprof endpoint, as well as when saving
  profiles to files on exit.

The following flags have been removed:
- `--profile-dir`: superseded by the `--diagnostics-output-directory` flag
- `--profile-blocking`: the `--profile-store-on-exit` flag enables blocking
  profiling. Use `--profile-blocking-rate=0` to explicitly disable it.
- `--profile-memory`: the `--profile-store-on-exit` flag enables memory
  profiling. Use `--profile-memory-rate=0` to explicitly disable it.
- `--profile-mutex`: the `--profile-store-on-exit` flag enables mutex
  profiling. Use `--profile-mutex-fraction=0` to explicitly disable it.

Add CLI test for profile flags.
2025-11-26 09:40:01 -08:00
Nathan Baulch ea1bdb1541 chore(ci): enable noctx linter (#4972)
* pass context in webdav helpers
* fix typo in function name
2025-11-19 21:46:28 -08:00
Julio Lopez 297673b4c4 chore(ci): cleanup TestKopiaRunner (#5010)
Remove unnecessary environment variable cleanup in test.
Cleanup is done via `t.Setenv(...)`

Leverage require in TestKopiaRunner
2025-11-18 20:02:48 -08:00
Julio Lopez 7586b21b1f chore(general): use contexts in tests (#5009)
Ref:
- Subset of the changes proposed by @NathanBaulch in #4972
2025-11-18 17:47:23 -08:00
Julio Lopez 7db061ee71 build(deps): Go 1.25 (#4987)
Upgrade to Go 1.25
Leverage `WaitGroup.Go` in Go 1.25
2025-11-17 16:42:12 -08:00
Julio Lopez 070c15b888 chore(general): avoid wrapping always-nil error (#4997) 2025-11-16 22:55:35 -08:00
Julio Lopez 0875010b1e chore(general): fix typos (#4986)
- follow-up to #4985
2025-11-13 20:22:29 -08:00
Julio Lopez c60ebebb17 chore(ci): make socket activation test more robust (#4985)
Objective: make the tests more robust and reduce random failures.

Preliminary refactoring:
- Accept testing.TB in testenv helpers. This is needed to
  use `require.EventuallyWithT` in socket activation tests.
- Rename parameters for clarity

Tests refactoring:
- use t.Cleanup instead of defer where appropriate
- create file handlers in test routine instead of go routines
- remove unnecessary var declaration
- increased wait time to 30 seconds.
- allow running socket activation test on Darwin

Ref:
- #3283
- #3313
- #3318
2025-11-13 19:02:57 -08:00
Julio Lopez bb20d9e11a chore(ci): enable wsl_v5:{assign,expr} linter settings (#4982)
Enable wsl_v5 settings:
- assign
- expr
2025-11-12 23:12:06 -08:00
Nathan Baulch 657fda216a chore(ci): upgrade to golangci-lint 2.6.1 (#4973)
- upgrade to golangci-lint 2.6.1
- updates for gosec
- updates for govet
- updates for perfsprint
- updates modernize

Leaves out modernize:omitempty due to conflicts with tests
2025-11-11 21:27:10 -08:00
Julio Lopez 19af93f2b1 refactor(ci): enable wsl_v5:return linter (#4975)
Also, disable redundant nakedret linter
2025-11-11 16:53:10 -08:00
Julio Lopez 9931d1d03c fix(test): use safer t.Setenv (#4974)
TestServerCreateAndConnectViaAPI now runs sequentially
as required by t.Setenv to avoid conflicts with other tests.
2025-11-11 16:00:46 -08:00
Nathan BaulchandJulio Lopez 557940c524 chore(ci): upgrade to golangci-lint v2.5.0 (#4931)
Upgrades golangci-lint to v2.5.0

Enables:
- wsl_v5

Disables:
- embeddedstructfieldcheck
- noinlineerr (not used in this codebase)
- noctx (temporarily)
- godot
- wsl (deprecated)

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
2025-11-11 12:37:07 -08:00
lyndon-li 83bd4d45da feat(general): maintenance stats for drop deleted contents and compact indexes (#4948) 2025-11-04 11:40:20 -08:00
Julio Lopez 069018adca refactor(general): use explicit return values (#4940)
Add return values in long helper function. This Improves clarity
and avoids 'naked' return and removes `//nolint:nakedret` annotation.

Explicit return values for GetShardedPathAndFilePath
2025-10-30 23:14:58 -07:00
Julio Lopez 4cbd7026a6 refactor(general): leverage maps.Clone (#4905) 2025-10-23 19:45:29 -07:00
Julio Lopez 995e7fd893 refactor(general): modernize (#4903)
Applies the modernize changes for the following categories:

- mapsloop
- stringsseq
- stringscutprefix
- sortslice
2025-10-23 17:11:38 -07:00
Julio Lopez 36508f94be test(general): fix endurance test failures (#4859)
Prevent running "auto-maintenance" on snapshot create.

Ref:
- #4851

Context: the test fails because there are concurrent "endurance"
runners and each of these advances the clock, some of them
significantly (action{Small,Medium,Large}ClockJump), which
causes the clock skewness check to fail when
(auto-)maintenance runs.

The test maintenance action does not experience this issue
because it runs exclusively on its own, that is, other
actions have to wait until maintenance completes.
2025-10-01 18:30:47 -07:00
Jarek Kowalski 0f7253eb66 feat(general): rewrote content logs to always be JSON-based and reorganized log structure (#4822)
This is a breaking change to users who might be using Kopia as a library.

### Log Format

```json
{"t":"<timestamp-rfc-3389-microseconds>", "span:T1":"V1", "span:T2":"V2", "n":"<source>", "m":"<message>", /*parameters*/}
```

Where each record is associated with one or more spans that describe its scope:

* `"span:client": "<hash-of-username@hostname>"`
* `"span:repo": "<random>"` - random identifier of a repository connection (from `repo.Open`)
* `"span:maintenance": "<random>"` - random identifier of a maintenance session
* `"span:upload": "<hash-of-username@host:/path>"` - uniquely identifies upload session of a given directory
* `"span:checkpoint": "<random>"` - encapsulates each checkpoint operation during Upload
* `"span:server-session": "<random>"` -single client connection to the server
* `"span:flush": "<random>"` - encapsulates each Flush session
* `"span:maintenance": "<random>"` - encapsulates each maintenance operation
* `"span:loadIndex" : "<random>"` - encapsulates index loading operation
* `"span:emr" : "<random>"` - encapsulates epoch manager refresh
* `"span:writePack": "<pack-blob-ID>"` - encapsulates pack blob preparation and writing

(plus additional minor spans for various phases of the maintenance).

Notable points:

- Used internal zero allocation JSON writer for reduced memory usage.
- renamed `--disable-internal-log` to `--disable-repository-log` (controls saving blobs to repository)
- added `--disable-content-log` (controls writing of `content-log` files)
- all storage operations are also logged in a structural way and associated with the corresponding spans.
- all content IDs are logged in a truncated format (since first N bytes that are usually enough to be unique) to improve compressibility of logs (blob IDs are frequently repeated but content IDs usually appear just once).

This format should make it possible to recreate the journey of any single content throughout pack blobs, indexes and compaction events.
2025-09-27 17:11:13 -07:00
Julio Lopez e1e0423b8a refactor(general): increase number of retained maintenance run info (#4846) 2025-09-25 10:50:35 -07:00
Julio Lopez 24af54e55e refactor(cil): rename flag to --dangerous-commands (#4773) 2025-09-03 12:35:46 -07:00
Julio Lopez 70032f8498 refactor(cli): remove deprecated no-op flags (#4764)
Removes the following flags:
--caching: no-op
--list-caching: no-op
--enable-jaeger-collector: errors out when specified.

Also removes no-longer-used `deprecatedFlag` function.
2025-08-16 19:44:36 -07:00
Ankit Jain 35089a4894 feat(restore): added support for deleting extra files in restore path (#4725) 2025-07-17 07:10:32 +00:00
Julio Lopez 735adfcf85 refactor(general): small misc. cleanups (#4666)
* remove unnecessary type argument
* modernize with max
* unexport getPartial and update comment
* unexport getFull
* verifyNotCached helper
* use require helpers
* leverage verify[Not]Cached
* use windowsOSName const
* fix comment wrapping
* require in stat_test
* use 512 as the write size and log allocated size
* rename const to expectedMinAllocSize
* write a single byte to test file
* add TestGetBlockSizeFromCurrentFS
* require Positive
* log before invariant check
2025-06-13 23:56:37 -07:00
Nathan Baulch 19d92613a6 chore(general): typos (#4659) 2025-06-10 17:24:14 -07:00
Julio Lopez e1d065aee1 refactor(general): misc cleanups (#4652)
- use raw strings for readability, removes escaping
- clarify comment
- add self-documenting message to test assertion
- always cleanup test file
- refactor(test): cleanup TestParseSnapListAllExeTest
- nit: call getLogOutputPrefix once
- rename SkipTestUnlessLinux
- inline TestSkipUnlessCI
- rename SkipTestOnCIUnlessLinuxAMD64
2025-06-04 22:58:01 -07:00
Julio Lopez d91a5a8f94 chore(general): enable forcetypeassert linter (#4624)
- enable `forcetypeassert` linter in non-test files
- add `//nolint` annotations
- add `testutil.EnsureType` helper for type assertions
- enable `forcetypeassert` linter in test files
2025-05-31 23:17:38 -07:00
Julio Lopez 3d4c5f8f9e refactor(general): s/interface{}/any/ (#4614) 2025-05-29 06:07:49 +00:00
Julio Lopez eadcdc753d test(general): fix TestSnapshotNoLeftoverCheckpoints slowness (#4611)
Avoid allocating 1GB of RAM to write a test file.
Exclude test from race detector.

- Fixes: #4610
- Ref: #4439

nits:
- use `require.Greater`.
- add types to constants to used them with `require.*`.
- factor out function to write file with random data.
2025-05-28 19:01:01 -07:00
shniuboboandJarek Kowalski dd664b5554 fix(snapshots): Remove checkpoints after a complete snapshot (#4439)
* fix(snapshots): Remove checkpoints after a complete snapshot

... by setting start time of checkpoints one nanosecond earlier than
that of the snapshot.

* test(snapshots): Test for leftover checkpoints

* fix linter issues

* removed stray curly brace

---------

Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
2025-05-24 15:10:40 +00:00
Kopia Builder [bot]andJarek Kowalski 00e2db70ee feat(ui): upgraded htmlui to the latest version (#4565)
* feat(ui): upgraded htmlui to the latest version

* fixed TestByteRepresentation test

---------

Co-authored-by: Jarek Kowalski <jaak@jkowalski.net>
2025-05-12 05:15:34 +00:00
Rohit-BM18 12409c7279 feat(cli): --stats-only flag for the diff command (#4557)
Adds a `--stats-only` flag to the `diff` command to reduce
output verbosity.
When `kopia diff` is invoked with the `--stats-only` flag it
only outputs the aggregate statistics of changes.
2025-05-05 20:59:52 -07:00
Matthieu MOREL 8a176255c0 fix(general): enable wsl for all go files (#4524)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-26 13:01:20 -07:00
Matthieu MOREL b0827d128a fix(ci): remove gocritic unnecessaryDefer exclusion (#4525)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-25 14:47:08 -07:00
Julio Lopez 08dd138802 refactor(general): cleanup a few tests (#4519)
Cleanup robustness tests and `local_fs_test.go`
"Mechanical" changes: 
- Use `require` helpers
- Use `testing.T` helpers
 
Note change in functionality: The use of `require` helpers
stops tests once a check fails. Before, various checks
were using `t.Error`, which fails the test but allows the
test to continue its execution.


* refactor(general): cleanup robustness/snapmeta/kopia_persister_light_test.go

Use `require` helpers
Use `testing.T` helpers

* refactor(general): cleanup local_fs_test.go

* fix import order
2025-04-23 23:35:05 -07:00
Julio López e3fc6e012d refactor(general): leverage os.CreateTemp (#4513)
* use `os.CreateTemp` in `tempfile.CreateAutoDelete`
* refactor `TestTempFile`: add `VerifyTempfile` test helper
* add test for `createUnixFallback`
* rename function to `tempfile.CreateAutoDelete`
* remove the `dir` parameter to `tempfile.CreateAutoDelete`,
  only an empty string was passed, apart from test cases.
* guard against panic in TestShadowCopy
2025-04-22 20:55:11 -07:00
Julio López 09b88d3860 chore(general): minor cleanups and other nits (#4507)
* use uint8 for clarity
* unexport writeContentAsyncAndVerify
* fix typo in test function name
* remove commented interface functions
* use atomic.Int32
* cleanups in socket server activation test
* leverage stdlib's maps and slices packages
  replace uses of `golang.org/x/exp/maps`
* nit: leverage `maps.Values`
2025-04-16 23:25:01 -07:00
Matthieu MOREL 675e958877 chore(ci): bump golangci-lint to v2.1.2 (#4500)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-04-15 22:49:13 -07:00