Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/source-bookmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Bookmarks source checks
on:
push:
branches: [fix/build-bookmarks]
pull_request:
branches: [Bookmarks/develop]
permissions:
contents: read
jobs:
source:
uses: stadub/PowershellScripts/.github/workflows/validate-module-source.yml@d3fa5897213e3ff4e0d64897559bdfb516356512
with:
module: Bookmarks
source_sha: ${{ github.event.pull_request.head.sha || github.sha }}
automation_sha: d3fa5897213e3ff4e0d64897559bdfb516356512
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# File types to ignore globally
.history
.vscode
TestResults/
219 changes: 82 additions & 137 deletions Bookmarks/Bookmarks.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,158 +1,103 @@
$NoExport = $true
$ModuleDevelopment = $true
$DebugPreference = "Continue"

Set-StrictMode -version Latest

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

. $PSScriptRoot\Shared-Functions.ps1

. $PSScriptRoot\Functions.ps1

_Initalize

Describe "Remove-AllPSBookmarks" {

It "clear all bookmarks" {
$_marks["a"]="A"
$_marks["b"]="B"

$_marks.Count | Should -Not -Be 0

Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

Remove-AllPSBookmarks

$_marks.Count | Should -Be 0
# Exercise real CSV persistence in an isolated directory; never initialize a user profile.
Set-StrictMode -Version Latest
. $PSScriptRoot/Shared-Functions.ps1
. $PSScriptRoot/Functions.ps1

Describe 'Bookmark persistence and commands' {
BeforeEach {
$script:_marksPath = Join-Path $TestDrive 'Bookmarks.csv'
Remove-Item $script:_marksPath -ErrorAction SilentlyContinue
}
}

Describe "Add-PSBookmark" {

It "adds current folder to bookmarks" {
$_marks = @{ }
Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

Set-Location $here
Add-PSBookmark testDir1
$_marks.Count | Should -Be 1
$_marks.Keys | Should -Be "testDir1"
$_marks.Values | Should -Be $here
It 'starts with no bookmarks when the store does not exist' {
(Get-PSBookmarks).Count | Should -Be 0
}

It "adds selected folder to bookmarks" {
$_marks = @{ }
Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

Add-PSBookmark testDir2 "c:"
$_marks = Get-PSBookmarks
$_marks.Count | Should -Be 1
$_marks.Keys | Should -Be "testDir2"
$_marks.Values | Should -Be "c:"
It 'persists the current directory' {
$null = Add-PSBookmark here
(Get-PSBookmarks)['here'] | Should -BeExactly (Get-Location).Path
}

It "adds path from pipeline to bookmarks" {
$_marks = @{ }
Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

"c:" |Add-PSBookmark testDir3
$_marks = Get-PSBookmarks
$_marks.Count | Should -Be 1
$_marks.Keys | Should -Be "testDir3"
$_marks.Values | Should -Be "c:"
It 'persists explicit and pipeline paths including CSV punctuation and Unicode' {
$path = Join-Path $TestDrive ('a,b' + [char]0x2642)
$null = Add-PSBookmark explicit $path
$null = $path | Add-PSBookmark piped
$marks = Get-PSBookmarks
$marks.Count | Should -Be 2
$marks['explicit'] | Should -BeExactly $path
$marks['piped'] | Should -BeExactly $path
}
}


Describe "Remove-PSBookmark" {

It "remove bookmark from list" {
$_marks = @{ }
$_marks["a"]="A";

Mock -CommandName Import-Csv -MockWith {}
Mock -CommandName Export-Csv -MockWith {}

Mock -CommandName Restore-PSBookmarks -MockWith {} -Verifiable
Mock -CommandName Save-PSBookmarks -MockWith {} -Verifiable

$_marks.Count | Should -Be 1
$_marks.Keys[0] | Should -Be "a"
$_marks.Values[0] | Should -Be "A"

Remove-PSBookmark "a"

$_marks.Count | Should -Be 0

Assert-VerifiableMock
It 'rejects duplicates without replacing the saved path' {
$null = Add-PSBookmark a original
{ Add-PSBookmark a replaced } | Should -Throw
(Get-PSBookmarks)['a'] | Should -BeExactly 'original'
}

}

Describe "Open-PSBookmark" {

It "open specific bookmark" {
$_marks = @{ }
$_marks["a"]="A";

Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

Mock -CommandName Set-Location -MockWith {}

Open-PSBookmark "a"

Assert-MockCalled Set-Location 1

It 'removes one bookmark while preserving others' {
$null = Add-PSBookmark a first
$null = Add-PSBookmark b second
$null = Remove-PSBookmark a
$marks = Get-PSBookmarks
$marks.Count | Should -Be 1
$marks['b'] | Should -BeExactly 'second'
}
}

Describe "Update-PSBookmark" {

It "update current folder to bookmarks" {
$_marks = @{ }
Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

Add-PSBookmark testDir1 "c:"
It 'clears the persisted store' {
$null = Add-PSBookmark a first
Remove-AllPSBookmarks
(Get-PSBookmarks).Count | Should -Be 0
}

Set-Location $here
Update-PSBookmark testDir1
$_marks.Count | Should -Be 1
$_marks.Keys | Should -Be "testDir1"
$_marks.Values | Should -Be $here
It 'opens the persisted path' {
$null = Add-PSBookmark a $TestDrive
Mock Set-Location {}
Open-PSBookmark a
Assert-MockCalled Set-Location 1 -Exactly -ParameterFilter { $Path -eq $TestDrive }
}

It "Update selected folder in bookmarks list" {
$_marks = @{ }
Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable
It 'updates paths from an argument, pipeline, and current location' {
$null = Add-PSBookmark a first
$null = Update-PSBookmark a second
(Get-PSBookmarks)['a'] | Should -BeExactly 'second'
$null = 'third' | Update-PSBookmark a
(Get-PSBookmarks)['a'] | Should -BeExactly 'third'
$null = Update-PSBookmark a
(Get-PSBookmarks)['a'] | Should -BeExactly (Get-Location).Path
}

Add-PSBookmark testDir2 "c:"
It 'rejects updating a missing bookmark' {
{ Update-PSBookmark missing anything } | Should -Throw
(Get-PSBookmarks).Count | Should -Be 0
}

Update-PSBookmark testDir2 "$pwd"
$_marks = Get-PSBookmarks
$_marks.Count | Should -Be 1
$_marks.Keys | Should -Be "testDir2"
$_marks.Values | Should -Be "$pwd"
It 'reloads external session changes on every operation' {
$null = Add-PSBookmark a first
@([pscustomobject]@{ Key = 'a'; Value = 'external' },
[pscustomobject]@{ Key = 'b'; Value = 'other' }) |
Export-Csv $script:_marksPath -NoTypeInformation
$null = Add-PSBookmark c third
$marks = Get-PSBookmarks
$marks.Count | Should -Be 3
$marks['a'] | Should -BeExactly 'external'
$marks['b'] | Should -BeExactly 'other'
}

It "Update path from pipeline to bookmarks" {
$_marks = @{ }
Mock -CommandName Import-Csv -MockWith {} -Verifiable
Mock -CommandName Export-Csv -MockWith {} -Verifiable

Add-PSBookmark testDir3 "$pwd"
It 'returns an independent snapshot' {
$null = Add-PSBookmark a first
$marks = Get-PSBookmarks
$marks['a'] = 'mutated'
(Get-PSBookmarks)['a'] | Should -BeExactly 'first'
}
}

"c:" |Update-PSBookmark testDir3
$_marks = Get-PSBookmarks
$_marks.Count | Should -Be 1
$_marks.Keys | Should -Be "testDir3"
$_marks.Values | Should -Be "c:"
Describe 'Bookmark manifest export contract' {
It 'lists only implemented public functions without trailing whitespace' {
$manifest = Import-PowerShellDataFile (Join-Path $PSScriptRoot 'Bookmarks.psd1')
$expected = @('Add-PSBookmark', 'Remove-PSBookmark', 'Remove-AllPSBookmarks',
'Open-PSBookmark', 'Get-PSBookmarks', 'Update-PSBookmark')
($manifest.FunctionsToExport | Sort-Object) -join ',' |
Should -BeExactly (($expected | Sort-Object) -join ',')
foreach ($name in $expected) { (Get-Command $name).CommandType | Should -Be 'Function' }
}
}
}
2 changes: 1 addition & 1 deletion Bookmarks/Bookmarks.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FunctionsToExport = @('Add-PSBookmark',
'Remove-AllPSBookmarks',
'Open-PSBookmark',
'Get-PSBookmarks',
'Update-PSBookmark ')
'Update-PSBookmark')


# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
Expand Down
2 changes: 0 additions & 2 deletions Bookmarks/Bookmarks.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Export-ModuleMember -Function Add-PSBookmark
Export-ModuleMember -Function Remove-PSBookmark
Export-ModuleMember -Function Remove-AllPSBookmarks
Export-ModuleMember -Function Open-PSBookmark
Export-ModuleMember -Function Restore-PSBookmarks
Export-ModuleMember -Function Save-PSBookmarks
Export-ModuleMember -Function Get-PSBookmarks
Export-ModuleMember -Function Update-PSBookmark
. $PSScriptRoot\Aliases.ps1
50 changes: 49 additions & 1 deletion Bookmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,46 @@ Module import:
Import-Module Bookmarks
```

## Update checks

Bookmarks checks PowerShell Gallery at most once every 24 hours per user. Set
these environment variables **before importing** (for example, in your profile):

```powershell
# Disable automatic checks completely (no network or update-cache access).
$env:BOOKMARKS_UPDATE_CHECK = '0'
Import-Module Bookmarks
```

```powershell
# Enable checks, but only once a week.
$env:BOOKMARKS_UPDATE_CHECK = '1'
$env:BOOKMARKS_UPDATE_CHECK_INTERVAL_HOURS = '168'
Import-Module Bookmarks
```

`0`, `false`, and `off` disable checks (case insensitive). Unset or other values
leave checks enabled. The interval accepts whole hours from 1 through 8760;
unset, malformed, zero, negative, or out-of-range values use 24 hours.
Remove the variables to restore defaults.

A due check makes one request for the latest stable version, with a three-second
HTTP timeout and no redirects or retries. DNS resolution can take longer than
that timeout on some systems; disable checks for startup with no network delay.
Notifications use host output, never success-pipeline data. Offline and HTTP
errors are silent and attempts, including failures, wait the full interval before
retrying. The timestamp persists across imports and new shells in
`[Environment]::GetFolderPath('LocalApplicationData')/PowershellScripts/UpdateChecks/Bookmarks.timestamp`.
If the cache cannot be written or is busy, the check is skipped; simultaneous
imports claim the timestamp exclusively. Deleting this file makes the next
import eligible again. Bookmark files and commands are unaffected.

For maintainers: port the reviewed update-check functions and tests selectively
to the 7Zip and Currency helper copies on their own development/issue branches,
with module-specific control names and cache keys. Those ports are not included
here. Keep profile/storage helpers intact, then reconcile release packages through
the separate packaging/release process; do not copy whole stale helper files.

# Commands


Expand Down Expand Up @@ -189,4 +229,12 @@ a coffee or a beer is always appreciated. Thank you very much in advance.

If you have any idea or suggestion - please add a github issue.

<!-- https://www.contributor-covenant.org/version/1/4/code-of-conduct -->
<!-- https://www.contributor-covenant.org/version/1/4/code-of-conduct -->
## Source regression checks

Run `Invoke-Pester ./Bookmarks.Tests.ps1` with Pester 4.10.1. The suite uses real
CSV files under Pester's TestDrive and covers save/reload, external session edits,
add/update/remove/clear, pipeline paths, CSV punctuation, Unicode, and exports.
It does not initialize or write the user's bookmark profile. The public update
export is `Update-PSBookmark` (without trailing whitespace); storage helpers remain
private. Startup/update-check work is maintained separately in #24/#27.
Loading
Loading