Create settings files like server if they don't exist#238
Open
SharonStrats wants to merge 31 commits intomainfrom
Open
Create settings files like server if they don't exist#238SharonStrats wants to merge 31 commits intomainfrom
SharonStrats wants to merge 31 commits intomainfrom
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the profile/type-index initialization flow to create missing Settings resources (preferences + type index docs) in an idempotent way (no overwrites), and updates tests accordingly.
Changes:
- Change the default suggested preferences file name to
/Settings/prefs.ttl. - Add “create-if-missing with seeded content” helpers and use them to create type index documents with proper initial Turtle content.
- Ensure Settings container/ACL and public type index ACL are created when missing; update and expand tests to assert the new network/write behavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/utilityLogic.test.ts | Adds coverage for new utility helpers that create docs with seeded content and validate failure behavior. |
| test/typeIndexLogic.test.ts | Updates expectations for new Settings bootstrap requests and validates seeded type index content. |
| test/profileLogic.test.ts | Updates expected created URLs/content (prefs.ttl, ACLs, type indexes) and makes assertions more robust. |
| src/util/utils.ts | Switches suggested preferences file name to prefs.ttl. |
| src/util/utilityLogic.ts | Adds loadOrCreateWithContentOnCreate and followOrCreateLinkWithContentOnCreate; makes create operations conditional. |
| src/util/containerLogic.ts | Treats HTTP 409 as idempotent success when creating containers. |
| src/typeIndex/typeIndexLogic.ts | Uses the new “create with content” link helper for public/private type index creation. |
| src/typeIndex/typeIndexDocuments.ts | Introduces seeded Turtle document templates for public/private type indexes. |
| src/profile/profileLogic.ts | Adds Settings container + ACL setup, initializes preference defaults, creates type indexes/ACLs when missing, and adds caching/in-flight dedupe for loadPreferences. |
Comments suppressed due to low confidence (2)
src/profile/profileLogic.ts:317
- In this
catch, the code mixes optional chaining (err.response?.status === 404) with direct access (err.response.status === 401/403). Since errors thrown from the new initialization helpers can be plainErrorobjects (noresponse),err.response.statuscan throw and mask the real failure. Use optional chaining consistently (or normalize the status early) before branching on status codes.
try {
await store.fetcher.load(preferencesFile as NamedNode)
} catch (err) { // Maybe a permission problem or origin problem
const msg = `Unable to load preference of user ${user}: ${err}`
if (err.response?.status === 404) {
// Self-heal when a stale profile pointer references a missing preferences file.
await ensureOwnerOnlyAclForSettings(user, preferencesFile as NamedNode)
await ensurePreferencesDocExists(preferencesFile as NamedNode)
await initializePreferencesDefaults(user, preferencesFile as NamedNode)
await store.fetcher.load(preferencesFile as NamedNode)
return preferencesFile as NamedNode
}
debug.warn(msg)
if (err.response.status === 401) {
throw new UnauthorizedError()
}
if (err.response.status === 403) {
if (differentOrigin(preferencesFile)) {
throw new CrossOriginForbiddenError()
}
throw new SameOriginForbiddenError()
}
src/util/utilityLogic.ts:120
WebOperationErrorexpects a string message, but this code throwsnew WebOperationError(err), which will typically stringify to[object Object]and drop the contextualmsgyou just built. Thrownew WebOperationError(msg)(and include the original error details in that message) to preserve actionable error information.
} catch (err) {
const msg = `followOrCreateLink: Error making link in ${doc} to ${object}: ${err}`
debug.warn(msg)
throw new WebOperationError(err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Ticket SolidOS/solid-ui#464
The preference file, public type index, and private type index that were getting created were blank, this populates the files as done in the server upon registration for a new account. The Preferences file that was being created also was named Preferences.ttl, while the server creates prefs.ttl so that was also changed to match.
Lastly if the preferences file is missing it also looks for the public and private type indexes. The public type index is written to the webid profile as well as the prefs file, while the private index is only written to prefs as the specification indicates.