Skip to content

Create settings files like server if they don't exist#238

Open
SharonStrats wants to merge 31 commits intomainfrom
feature1
Open

Create settings files like server if they don't exist#238
SharonStrats wants to merge 31 commits intomainfrom
feature1

Conversation

@SharonStrats
Copy link
Copy Markdown

@SharonStrats SharonStrats commented Mar 29, 2026

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.

@SharonStrats SharonStrats self-assigned this Mar 29, 2026
Copilot AI review requested due to automatic review settings March 29, 2026 06:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 plain Error objects (no response), err.response.status can 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

  • WebOperationError expects a string message, but this code throws new WebOperationError(err), which will typically stringify to [object Object] and drop the contextual msg you just built. Throw new 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants