Skip to content

Fixing pull --beta and refactoring along the way#1084

Merged
josephjclark merged 18 commits intorelease/nextfrom
use-workspace-in-pull
Oct 24, 2025
Merged

Fixing pull --beta and refactoring along the way#1084
josephjclark merged 18 commits intorelease/nextfrom
use-workspace-in-pull

Conversation

@josephjclark
Copy link
Copy Markdown
Collaborator

@josephjclark josephjclark commented Oct 21, 2025

Had to get an old state.json format for Elias and it turned into a nightmare

Basically pull was written before a lot of our nice Workspace APIs and stuff, and was rushed out even then

And what's happening is the pull isn't using config properly from the openfn.yaml file

This PR basically plugs in the Workspace class to make life easier.

But I hit loads of little problems on the way - the code here is super messy and we really need to tidy up a bit

Fixes #1083

Headline changes

  • Rename project.repo to project.config
  • Generally renamed the repo/config stuff do "Workspace Config", or variations of
  • Centralised option parsing into a single file, which sets defaults
  • Introduced a new project.yaml format ({ project, workspace })
  • Standardised and simplified how we load openfn.yaml

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to know!):

  • Code generation (copilot but not intellisense)
  • Learning or fact checking
  • Strategy / design
  • Optimisation / refactoring
  • Translation / spellchecking / doc gen
  • Other
  • I have not used AI

You can read more details in our Responsible AI Policy

@github-project-automation github-project-automation bot moved this to New Issues in Core Oct 21, 2025
const { OPENFN_API_KEY, OPENFN_ENDPOINT } = process.env;

const config: Partial<Config> = {
const cfg: Partial<Config> = {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This old config stuff was just a cheap way to use the old deploy API. We need to phase it out soon


// TODO is outputRoot the right dir for this?
const workspace = new Workspace(outputRoot);
const config = workspace.getConfig();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not a fan of the getter - I just want to use workspace.config here. Why make it private?

@josephjclark josephjclark changed the title trying to enable old json formats Fixing pull --beta and refactoring along the way Oct 21, 2025
@josephjclark josephjclark marked this pull request as draft October 21, 2025 17:23

const project = Project.from('state', data, {
endpoint: config.endpoint,
repo: config,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The second argument here needs the same structure as new Project

So basically I'm passing state (as string, yam or json, maybe even as a file path?) and we'll load all the values from that state file. But if I want to override anything, or add context which the state file doesn't have, all that stuff just goes on the second argument.

const workflowsRoot = path.resolve(
outputRoot,
project.repo?.workflowRoot ?? 'workflows'
project.repo.dirs?.workflows ?? 'workflows'
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Shouldn't need any of this optional chaining bullshit: I want good robust config with everything defaulted

// workspace-wide configuration options
// these should be shared across projects
// and saved to an openfn.yaml file
// TODO should this just be the Workspace now?
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The hestitation is that there's a bit of circularity between Project and Workspace. I should be able to have one without the other - but they're actually coupled a bit nastily through config.

Needs more thought

@josephjclark
Copy link
Copy Markdown
Collaborator Author

Here's the plan to tidy some of this stuff up:

  • openfn.yaml is the Workspace Configuration file. It contains configuration for the workspace
  • So the repo options are just configuration
  • A Project may have an associated Workspace
  • Project and Workspace will both default config from the same place
  • A Project always has config (which may be a proxy for Workspace config)

@josephjclark
Copy link
Copy Markdown
Collaborator Author

Oh and openfn.yaml needs to look like this:

project:
workspace:

That gives you metadata about the checked out project, and config for the workspace generally

We should support legacy and new file formats for a while, but always serialize to the new

@doc-han
Copy link
Copy Markdown
Collaborator

doc-han commented Oct 22, 2025

From reading the description. we want to use workspace class in pull command.
An edge case is that, pull command can work in any empty directory but then the workspace class only works in a directly that has an openfn project previously pulled into it. Hence, if pull depends on the current state of workspace, we might not be able to pull into a new empty directory.

maybe init is needed? so then pull becomes
pull = init? + fetch + expand to filesystem

? - run if not already run

@josephjclark
Copy link
Copy Markdown
Collaborator Author

Yeah, something like that.

Either the CLI can run openfn init on an empty directory. Or we can have something like Workspace.fix() which generates a workspace with default values. Or we ask the user.

pull doesn't really need to care if it runs in a valid directory or not - it should just do what it needs to do. That's a different usecase to eg openfn project, which can only run in a valid workspace

@josephjclark
Copy link
Copy Markdown
Collaborator Author

Really need to wrap this up so I think I'm going to pause the "a Project should reference its workspace" thing and open a new issue

I think there are big improvements here, and it seems to work, so I'm going to declare victory ASAP

@josephjclark
Copy link
Copy Markdown
Collaborator Author

openfn.yaml now looks like this:

project:
  uuid: d3367267-ef25-41cf-91b2-43d18f831f3c
  endpoint: https://app.staging.openfn.org
  env: project
  inserted_at: 2025-10-21T17:10:57Z
  updated_at: 2025-10-21T17:10:57Z
workspace:
  dirs:
    projects: .projects
    workflows: workflows
  formats:
    openfn: yaml
    project: json
    workflow: json

Old yaml files, pre 0.6, are still 100% compatible. Very few tests have updated to the new structure.

👨‍🍳 💋

@josephjclark josephjclark marked this pull request as ready for review October 22, 2025 15:01
@@ -0,0 +1,5 @@
---
'@openfn/project': patch
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll recycle all this into a better patch note on release

This PR fixes a bug where workspace config settings are not properly respected by pull. This must be known.

@josephjclark josephjclark requested a review from doc-han October 22, 2025 15:01
@josephjclark
Copy link
Copy Markdown
Collaborator Author

@doc-han When you get a chance I'd like you to have a close look over this please: partly for your opinions (this is the right thing to do right??) but also to keep you in-sync with the changes. There's more work I want to do and you might be "it" for the next ticket

t.is(result.content, 'x: 1');
});

test('find openfn.json', (t) => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@doc-han thank you for the project integration tests! They caught an issue here which would have resulted in a big breakage 😬

@josephjclark josephjclark changed the base branch from main to release/next October 22, 2025 16:04
Copy link
Copy Markdown
Collaborator

@doc-han doc-han left a comment

Choose a reason for hiding this comment

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

I don't have much issue with the code here. looks fine. my only issue has to do with some typings(Typescript) not being strict.

@josephjclark
Copy link
Copy Markdown
Collaborator Author

@doc-han agreed - let's try and fix those as we go. We should be striving to improve the typing and general semantics on every PR from here going forward - I welcome your contributions in cleaning this all up!

@josephjclark josephjclark merged commit edfc759 into release/next Oct 24, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from New Issues to Done in Core Oct 24, 2025
@josephjclark josephjclark deleted the use-workspace-in-pull branch October 24, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

pull --beta doesn't respect openfn.yaml

3 participants