GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test(aws): add S3 contract tests by mbevc1 · Pull Request #1065 · kosli-dev/cli

Conversation

@mbevc1

@mbevc1 mbevc1 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

runS3ContractTests asserts the S3 behaviours this codebase depends on:
object listing, continuation-token pagination, object download, and the
error responses for unknown buckets and missing keys.

The suite runs against both FakeS3Client (always) and real AWS (gated on
credentials), so the fake cannot drift from the real API unnoticed.

Related #758

Checklist

  • Docs are autogenerated from CLI help — make sure the help text reflects your changes
  • Helm chart (charts/k8s-reporter/) updated, if needed. Note: these changes live in a separate PR
  • Terraform provider and related changes (terraform-provider-kosli, terraform-aws-evidence-reporter, terraform-aws-kosli-reporter) updated, if needed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mbevc1 mbevc1 added go Pull requests that update go code testing labels Jul 31, 2026
@claude

claude Bot commented Jul 31, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Claude finished @mbevc1's task in 2m 51s —— View job


PR Review: S3 contract tests

  • Static analysis (go build, go vet, go mod tidy — all clean)
  • Read changed files
  • Review for quality, edge cases, bugs
  • Post review

This is a well-constructed PR. The dual-target contract suite (fake + gated real-AWS) is exactly the right shape to stop the fake from drifting, and the seam design is clean.

Static analysis

  • go build ./... ✅ go vet ./... ✅ go mod tidy → no diff ✅
  • I could not run the test suite in this sandbox (go test needs an approval that isn't granted to this job), so the pass/fail claims below are from reading, not execution. CI covers the run.

Strengths

  • The seam split is genuinely thoughtful. Keeping ListObjectsV2 at SDK level means s3.NewListObjectsV2Paginator still runs against your interface, so the continuation-token contract is verified against real S3 rather than a hand-rolled paginator — while DownloadObject sits at operation level to avoid reimplementing the transfer manager's ranged GetObject/HeadObject. The ADR update explains this trade-off crisply.
  • TestGetS3DataFromClientFilterEquivalence is a nice technique — asserting "filter the full bucket == a bucket that only ever held the subset" pins down filter semantics without hardcoding directory digests that would be brittle.
  • The fake's contract-vs-fake-only test separation is disciplined — error injection and the MaxKeys/negative-token rejections are correctly kept out of runS3ContractTests (with comments explaining why), since real S3 wouldn't behave that way.
  • The prior review's hardening suggestions are fully addressed — MaxKeys < 1 and negative continuation tokens are now rejected (fake_s3.go:89-107), each with a dedicated fake-only test. No infinite-loop / panic footgun remains.
  • WriterAt-nil validation and the strings.HasSuffix(key, "/") folder-marker skip line up correctly with the fixtures.

Minor / optional (nothing blocking)

  1. Timestamp coupling — fakeS3LastModified (fake_s3.go:18, 2024-01-15 10:30) and the earlier value in aws_test.go are the same instant by hand. The "newest timestamp" case sets lastModified explicitly so there's no hidden dependency today, but if someone edits one constant the coincidence is easy to miss. A one-line comment noting they're intentionally equal (or deriving one from the other) would future-proof it.
  2. Global factory mutation in snapshotS3_test.go — SetupTest writes the package global aws.NewS3ClientFunc and TearDownTest resets it. As you noted in the thread, this is safe here (no t.Parallel(), -p=8 is process-level, and it mirrors the existing NewLambdaClientFunc seam), so I agree it's fine and consistent. Worth keeping in mind only if S3 command tests ever gain t.Parallel().
  3. FakeS3Client map reads under concurrency — agree with your assessment: the fake never writes to its receiver and concurrent map reads are safe, so there's no race. No change needed.

Verdict

Looks good to merge. The observations above are all optional polish — I found no correctness bugs, and the previously-raised hardening items are resolved.
· 20260731_s3_contract_testing

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

claude[bot]
claude Bot reviewed Jul 31, 2026
View reviewed changes
Comment thread internal/aws/fake_s3.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mbevc1
mbevc1 marked this pull request as ready for review July 31, 2026 13:42
@mbevc1
mbevc1 enabled auto-merge (squash) July 31, 2026 13:42
@mbevc1

mbevc1 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Comments on the observations:

  • Global factory / t.Parallel() - no t.Parallel() in either package, and -p=8 is package-level parallelism (separate processes), so the two packages can't race on the global at all. Same point as the Claude's first review; NewLambdaClientFunc and the GitHub seam share the property, so fixing only S3 would be inconsistent.
  • Unsynchronised map access - I think the review is wrong and FakeS3Client never writes to its receiver (no f.X = … in the file), and concurrent reads of a Go map are safe. Similar approach is with Lambda.
  • sortedKeys() per page - not needed now
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mbevc1 added 9 commits July 31, 2026 14:45
@mbevc1
refactor(aws): extract an S3API seam for GetS3Data
704f83c
Introduce `S3ListAPI` (ListObjectsV2) and `S3DownloadAPI` (DownloadObject),
combined into `S3API`, plus a `NewS3ClientFunc` factory that tests can replace.
The real `*s3.Client` and `*transfermanager.Client` satisfy their half of the
interface implicitly, so no adapter is needed.

Split `GetS3Data` into a credentials-to-client entry point and
`getS3DataFromClient`, mirroring the existing Lambda seam.
@mbevc1
test(aws): add S3 contract tests and FakeS3Client
504e6a6
`runS3ContractTests` asserts the S3 behaviours this codebase depends on:
object listing, continuation-token pagination, object download, and the
error responses for unknown buckets and missing keys.

The suite runs against both `FakeS3Client` (always) and real AWS (gated on
credentials), so the fake cannot drift from the real API unnoticed.
@mbevc1
test(aws): add fake-backed unit tests for S3 bucket harvesting
35ec012
Cover the paths real AWS cannot exercise cheaply: path and regex filters,
folder-marker skipping, single-file versus directory fingerprinting and
naming, multi-page listing, the newest-matched-object timestamp, and error
propagation from listing and download.

Filter selection is pinned by asserting that filtering the full bucket
fingerprints identically to a bucket holding only the expected subset,
which avoids hardcoding directory digests.

This also gives `--include-regex` / `--exclude-regex` their first end-to-end
coverage.
@mbevc1
test(cmd): run the snapshot s3 tests against a fake S3 client
9cc5a80
Inject `FakeS3Client` via `NewS3ClientFunc` in `SetupTest` and restore the real
factory in TearDownTest, so all 11 cases run without AWS credentials.

Three of these cases previously called live S3 with no credential gate at
all, so they failed for anyone without AWS credentials; CI only masked it
because the main test job configures them.
@mbevc1
test(aws): trim TestGetS3Data to real-AWS smoke cases
b018404
Reduce the live-S3 table from 10 cases to 4: the two credential and region
error paths, a whole-bucket happy path, and one include-path case that keeps
its fingerprint so drift in the test bucket is still detected.

The nested-path, leading-slash and exclude cases now live in the fake-backed
tests, where their fingerprints come from fixtures rather than live bucket
content.

Run the S3 contract tests against real AWS from make test_contract_aws.
@mbevc1
docs(adr): record when to fake at SDK level vs operation level
dc98012
The ADR claimed we always fake at the operation level, but that only
described GitHub: LambdaAPI and ECSServicesAPI are SDK-level interfaces.

State the rule we actually follow — prefer SDK-level when the SDK client is
an ordinary Go type a fake can implement directly, fall back to
operation-level when that would mean reimplementing SDK machinery — and use
S3 as the worked example of a seam that mixes both.
@mbevc1
fix(aws): satisfy ST1005 in the S3 fake's error strings
1a01f89
staticcheck flags an error string whose first word is an ordinary
capitalized word, which failed the Lint job on two of the fake's
argument checks.

The sibling fakes escape the check only because their leading words
("FunctionName", "InvalidParameterException", "WriterAt") contain internal
capitals and read as identifiers. Reword all three of this file's argument
errors to start lowercase while still naming the SDK input field.
@mbevc1
fix(aws): reject out-of-contract ListObjectsV2 input in the S3 fake
18fd0cd
Two odd inputs made the fake misbehave in ways real S3 would not:

- MaxKeys of 0 gave every page zero objects while IsTruncated stayed true
  and the continuation token repeated, so s3.ListObjectsV2Paginator would
  spin forever.
- A negative continuation token parsed fine via strconv.Atoi and then
  indexed the key slice out of range.

Reject both rather than clamping them. Nothing in this package sets
MaxKeys, so values below 1 sit outside the contract verified against real
S3, and silently substituting a different page size is the kind of
fake/real divergence contract tests exist to catch.

The two new cases go in the fake-only block: real S3 accepts these inputs
without erroring, so asserting on them in runS3ContractTests would break
the real-AWS run.
@mbevc1
refactor(aws): validate the S3 fake's WriterAt with the other inputs
a33359b
DownloadObject looked the object body up before checking WriterAt, so a nil
WriterAt combined with a missing key reported "object not found" instead of
the programming error that actually caused it.

Move the check up beside the Bucket and Key checks, so all required-input
validation happens together and the more specific diagnostic wins.
@mbevc1
mbevc1 force-pushed the 20260731_s3_contract_testing branch from bbbcb20 to a33359b Compare July 31, 2026 13:45
AlexKantor87
AlexKantor87 approved these changes Jul 31, 2026
View reviewed changes
@mbevc1
mbevc1 merged commit 58e2f98 into main Jul 31, 2026
20 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mbevc1
mbevc1 deleted the 20260731_s3_contract_testing branch July 31, 2026 14:11
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
HarmonybrewBot HarmonybrewBot
!15762 merge bump-kosli-cli-2.36.4 into main
5361d66
kosli-cli 2.36.4

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>- Added `pull_request`, `merge_request` as additional command aliases for `assert pullrequest` and `attest pullrequest` (alongside existing `pr`, `mr`, `mergerequest`).
- Fixed a bug where packaging multiple evidence paths (e.g. `--attachments`) would fail with "operation not permitted" when any attachment was owned by a different user (e.g. files written by a Docker container). Ownership is no longer preserved during staging.
- Improved error messages when an evidence attachment path cannot be packaged: the error now names the path the user provided rather than an internal temp directory.

## What's Changed
* chore: add cmd aliases by @mbevc1 in kosli-dev/cli#1066
* test(aws): add S3 contract tests by @mbevc1 in kosli-dev/cli#1065
* fix(docs): separate flag types into a column by @mbevc1 in kosli-dev/cli#1068
* chore(deps): bump the github-actions-dependencies group with 2 updates by @dependabot[bot] in kosli-dev/cli#1070
* chore(deps): bump the go-dependencies group with 10 updates by @dependabot[bot] in kosli-dev/cli#1071
* fix(attest): don't preserve file ownership when packaging attachments by @mbevc1 in kosli-dev/cli#1076


**Full Changelog**: https://github.com/kosli-dev/cli/compare/v2.36.3...v2.36.4</pre>
  <p>View the full release notes at <a href="https://github.com/kosli-dev/cli/releases/tag/v2.36.4">https://github.com/kosli-dev/cli/releases/tag/v2.36.4</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!15762
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@claude claude[bot] claude[bot] left review comments
@AlexKantor87 AlexKantor87 AlexKantor87 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

go Pull requests that update go code testing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@mbevc1 @AlexKantor87
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.