feat: add bdstorage status subcommand — passive vault inspection without filesystem re-scan#63
Merged
Merged
Conversation
…hout filesystem re-scan
…hout filesystem re-scan
Contributor
Author
|
Hi @Rakshat28 This PR delivers the complete
Happy to address any feedback or adjustments based on your review! 🚀 |
Owner
|
@Itzzavdheshh Please resolve merge conflict(s) and make sure feature added by last merged PR(which plays with the option of changing default vault location) is also integrated with this. |
Contributor
Author
|
Hello @Rakshat28, I have made the requested changes. Please confirm whether everything is now updated according to your suggestions. Also, it would be a big help if you could add the appropriate type labels to the PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#Program
NSOC & GSSOC
feat:
bdstorage statusSubcommand — Passive Vault Summary & JSON OutputCloses #43
What This PR Does
Adds a new
bdstorage statussubcommand that retrieves all vault metrics directly from the existingredbdatabase — zero filesystem re-scan, zero I/O overhead. Users can now instantly answer "how much space has been saved so far?" without triggering an expensivescanordeduperun.Core output introduced:
JSON mode (
--jsonflag):{ "vault_location": "~/.imprint/store/", "objects_in_vault": 1234, "total_vault_size": 4928937164, "tracked_paths": 3891, "estimated_savings": 12025757286, "deduplication_ratio": 3.38 }Problem
scanordedupe"How much space has been saved?"required expensive I/O — unusable in monitoring scripts or dashboardsredbdatabase (~/.imprint/state.redb) already tracked all required metrics — but had no read APIstatusis called before any vault has been createdSolution
A
statussubcommand reading exclusively fromFILE_INDEXandCAS_INDEXredb tables. AVaultSummarystruct with fullserdesupport. Human-readable formatted output using the existingcoloredcrate. A--jsonflag for machine-readable output. A clear early-exit error when no vault exists. Unit tests for summary computation logic. Integration tests for both text and JSON modes.Changes — Deep Dive
1.
src/state.rs—VaultSummaryStruct +compute_summary()New
VaultSummarystruct:serde::Serialize+serde::Deserializederived — ready for--jsonoutput and testingPartialEqderived — enables direct equality assertions in unit testscompute_summary()implementation:FILE_INDEXread-only — single pass buildsHashMap<hash → size>CAS_INDEX— filters for entries withrefcount > 0that physically exist on disk in the sharded vaultFILE_INDEXCAS_INDEXentries withrefcount > 0confirmed present on disksize × (refcount - 1)for every vaulted hash(total_vault_size + estimated_savings) / total_vault_size; defaults to1.0whentotal_vault_size == 0redb::ReadableTableimported — enables read-only iteration over tablesNew unit tests:
test_compute_summary— populates mock state DB with duplicate and unique entries; asserts savings and deduplication ratio match expected valuestest_compute_summary_ignores_missing_vault_objects— validates that index entries without corresponding physical vault files are excluded from all metrics2.
src/main.rs—StatusSubcommand Registration + ExecutionCommandsenum — new variant:--jsonis a local flag scoped tostatusonly — does not affectdedupeorscanclap— appears correctly inbdstorage --helpandbdstorage status --helpExecution in
run():~/.imprint/state.redbdoes not exist:open_readonly_if_exists()— zero write riskcompute_summary()→ formats output based on--jsonflagFormatting helpers added:
format_number(val: usize)— space-delimited thousands (e.g.1 234,3 891)format_bytes(bytes: u64)— human-readable with one decimal place (KB,MB,GB,TB)print_vault_status(summary: &VaultSummary)— neatly aligned output usingcoloredcrate; replaces absolute home directory path with~shortcut; formats ratio with×character3.
tests/integration_tests.rs— Two New Integration Teststest_status_command:bdstorage statusexits with failure code on uninitialized environmentdedupeto initialize the vaultbdstorage status(text mode) prints all required fields: vault location, objects, vault size, tracked paths, savings, ratiobdstorage status --jsonproduces valid, parseable JSON with correct structural fields and accurate valuestest_status_after_scan_without_vault_fails:scan(withoutdedupe) then callingstatusexits cleanly with the "no vault found" error — not a panic, not a crashFiles Changed
src/state.rsVaultSummarystruct,compute_summary(),ReadableTableimport, 2 unit testssrc/main.rsStatusvariant,run()wiring, 3 formatting helperstests/integration_tests.rsError Handling
bdstorage statuswith no vault exits with non-zero code and clear messagebdstorage statusafterscan(nodedupe) exits with non-zero code and clear messageTesting
state::tests::test_compute_summary— okstate::tests::test_compute_summary_ignores_missing_vault_objects— oktest_status_command— oktest_status_after_scan_without_vault_fails— okcargo fmt --all -- --check— Passcargo clippy --all-targets --all-features -- -D warnings— Passcargo test— all tests passNo Regression
bdstorage scanoutput and behaviour unchangedbdstorage dedupeoutput and behaviour unchangedstatus— zero write risk to existing vault state🧪 How to Test
Test Checklist — Text Mode
bdstorage statusbefore anydedupe→ verify clean error message, non-zero exitbdstorage scan /paththenbdstorage status(no dedupe) → verify clean error, non-zero exitbdstorage dedupe /path→ runbdstorage status→ verify all 6 fields present1 234not1234)4.7 GBnot5049942220)×character (3.38×)~not absolute home directoryTest Checklist — JSON Mode
bdstorage status --json→ pipe tojq .→ verify valid formatted JSONbdstorage status --json | jq .objects_in_vault→ verify numeric value returnedbdstorage status --json | jq .deduplication_ratio→ verify float value returnedbdstorage status --json | jq .estimated_savings→ verify numeric value returnedbdstorage status --jsonbefore vault exists → verify non-zero exit, error to stderr, no JSON on stdoutTest Checklist — Metric Accuracy
dedupebdstorage status→ verifyobjects_in_vault= 2 (1 deduped + 1 unique)estimated_savings≈ 200MB (2 redundant copies of the 100MB file)tracked_paths= 4bdstorage status→ verify it is excluded from countsTest Checklist — No Regression
bdstorage dedupe /path→ output identical to pre-PRbdstorage scan /path→ output identical to pre-PRcargo test→ all pre-existing tests still passScreenshots
1.

bdstorage status— text mode, full formatted output2.

bdstorage status --json— raw JSON output3.

bdstorage status --json | jq .estimated_savings— piped to jq4.

bdstorage statusbefore vault exists — clear error message5.

bdstorage statusafterscanbut beforededupe— clean failure6.

cargo test— all tests passing including new unit + integration tests7.

cargo clippy— zero warnings8. Metric accuracy —

estimated_savingsanddeduplication_ratioverified against known fixture✅ Checklist
cargo testfeat: add bdstorage status subcommand — passive vault inspection without filesystem re-scanbdstorage statusreads DB only — zero filesystem re-scan triggeredbdstorage status --jsonproduces valid JSON parseable byjqscanwithoutdedupefollowed bystatusexits cleanly with descriptive errorVaultSummarystruct derivesSerialize,Deserialize, andPartialEqstatustest_compute_summaryunit test passes — oktest_compute_summary_ignores_missing_vault_objectsunit test passes — oktest_status_commandintegration test passes — oktest_status_after_scan_without_vault_failsintegration test passes — okcargo fmt --all -- --check— Passcargo clippy --all-targets --all-features -- -D warnings— Passscananddedupesubcommands fully unaffected — zero regressionunsafeblocks introducedContribution Note
Hi @Rakshat28
This PR delivers the complete
bdstorage statussubcommand as described in the issue — every acceptance criterion met, every edge case handled, and all CI checks passing.statusreads exclusively fromFILE_INDEXandCAS_INDEXredb tables; the filesystem is never walked~shortcut), objects in vault, total vault size, tracked paths, estimated savings, deduplication ratio with×--jsonflag —VaultSummaryfully serialised viaserde_json; pipes cleanly tojqscanwithoutdedupe→ same; no panics, no cryptic redb errorsVaultSummarystruct —Serialize + Deserialize + PartialEqderived; used in both output and test assertionsstate.rs(summary computation + missing vault object exclusion), 2 integration tests (text+JSON mode, scan-without-dedupe guard)cargo fmt,cargo clippy,cargo test— all three CI gates pass cleanscananddedupepathsHappy to address any feedback or adjustments based on your review! 🚀
Labels
#feature#cli#rust#redb#vault#status-command#json-output#serde#unit-tests#integration-tests#performance#NSoC26#nsoc#GSSOCSubmitted as part of Open Source Contribution — NSoC (Nexus Spring of Code) & GSSoC